Class: ExtraLoop::ExtractorBase

Inherits:
Object
  • Object
show all
Defined in:
lib/extraloop/extractor_base.rb

Overview

Pseudo Abstract class from which all extractors inherit. This should not be called directly

Direct Known Subclasses

CsvExtractor, DomExtractor, JsonExtractor

Defined Under Namespace

Modules: Exceptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_name, environment, *args) ⇒ ExtractorBase

Public: Initialises a Data extractor.

Parameters:

field_name  - The machine readable field name
environment - The object within which the extractor callback will be run (using run).
selector:   - The css3 selector to be used to match a specific portion of a document (optional).
callback    - A block of code to which the extracted node/attribute will be passed (optional).
attribute:  - A node attribute. If provided, the attribute value will be returned (optional).

Returns itself



26
27
28
29
30
31
32
33
34
35
# File 'lib/extraloop/extractor_base.rb', line 26

def initialize(field_name, environment, *args)
  @field_name = field_name
  @environment = environment

  @selector = args.find { |arg| arg.is_a?(String)}
  args.delete(@selector) if @selector
  @attribute = args.find { |arg| arg.is_a?(String) || arg.is_a?(Symbol) }
  @callback = args.find { |arg| arg.respond_to?(:call) }
  self
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



11
12
13
# File 'lib/extraloop/extractor_base.rb', line 11

def field_name
  @field_name
end

Instance Method Details

#parse(input) ⇒ Object



38
39
40
# File 'lib/extraloop/extractor_base.rb', line 38

def parse(input)
  raise Exceptions::ExtractorParseError.new "input parameter must be a string" unless input.is_a?(String)
end