Module: Scruber::Core::Extensions::CsvOutput::CoreMethods

Defined in:
lib/scruber/core/extensions/csv_output.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ void

This method returns an undefined value.

Registering method missing callbacks on including to crawling class

Parameters:

  • base (Class)

    class where module was included



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/scruber/core/extensions/csv_output.rb', line 40

def self.included(base)
  Scruber::Core::Crawler.register_method_missing /\Acsv_(\w+)_file\Z/ do |meth, scan_results, args|
    file_id = scan_results.first.first.to_sym
    path, options = args
    options = {} if options.nil?
    csv_file path, options.merge({file_id: file_id})
    Scruber::Core::Crawler.class_eval do
      define_method "csv_#{file_id}_out".to_sym do |fields|
        Scruber::Core::Extensions::CsvOutput.csv_out(file_id, fields)
      end
    end
  end
end

Instance Method Details

#csv_file(path, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/scruber/core/extensions/csv_output.rb', line 20

def csv_file(path, options={})
  file_id = options.fetch(:file_id) { :default }.to_sym
  options.delete(:file_id)
  Scruber::Core::Extensions::CsvOutput.register_csv file_id, path, options
  on_complete -1 do
    Scruber::Core::Extensions::CsvOutput.close_all
  end
end

#csv_out(fields) ⇒ Object



29
30
31
# File 'lib/scruber/core/extensions/csv_output.rb', line 29

def csv_out(fields)
  Scruber::Core::Extensions::CsvOutput.csv_out :default, fields
end