Class | Scrubyt::Export |
In: |
lib/scrubyt/output/export.rb
|
Parent: | Object |
Exports the given extractor (specified by it‘s root pattern) from the given file
input_file - the full path of the file where the extractor was defined. This can be achieved by calling
pattern.export(__File__)
from the file of the extractor definition.
parameters
root_pattern - the root pattern of the extractor. This is the variable ‘something’ in such a call:
something = Scrubyt::Extractor.define ...
However, since the export method should not be called directly (pattern is calling it), you will probably never need to care about this parameter.
output_file_name - the name of the file where the exported extractor should be dumped; From default (i.e. if you don‘t specify this parameter) this is "#{wrapper_name}_extractor_export.rb". You may override this setting if specifying this optional parameter.
extractor_result_file_name - the name of the file, where the result of the exported extractor should be dumped - for example, if output_file_name is "foo.rb" and extractor_result_file_name is "bar.xml", the extractor is exported to a file named "foo.rb", and after running "foo.rb", the results will be dumped to the file "bar.xml" If this option is not specified, the result is dumped to standard output as XML.
Examples:
camera_data = Scrubyt::Extractor.define do Action.fetch File.join(File.dirname(__FILE__), "input.html") P.item_name "Canon EOS 20D SLR Digital Camera (Lens sold separately)" end camera_data.export(__FILE__)
This will export this extractor to a file called "camera_data_extractor_export.rb". If "camera_data_extractor_export.rb" will be executed, the result will be dumped to the standard output.
Note that the export method in the last line belongs to the class Scrubyt::Pattern and not to Scrubyt::Export (i.e. this class). Scrubyt::Pattern.export will call Scrubyt::Export.export.
camera_data = Scrubyt::Extractor.define do Action.fetch File.join(File.dirname(__FILE__), "input.html") P.item_name "Canon EOS 20D SLR Digital Camera (Lens sold separately)" end camera_data.export(__FILE__, 'my_super_camera_extractor.rb', '/home/peter/stuff/result.xml')
This snippet will export the extractor to a file named ‘my_super_camera_extractor.rb’. After running ‘my_super_camera_extractor.rb’, the result will be dumped to the file ’/home/peter/stuff/result.xml’.