Class: DocWrapper::MultiPropertyDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/doc_wrapper/multi_property_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property_name, selectors, options, block) ⇒ MultiPropertyDefinition

Returns a new instance of MultiPropertyDefinition.



5
6
7
8
9
10
# File 'lib/doc_wrapper/multi_property_definition.rb', line 5

def initialize (property_name, selectors, options, block)
  @property_name = property_name
  @selectors = selectors
  @options = options
  @block = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/doc_wrapper/multi_property_definition.rb', line 3

def block
  @block
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/doc_wrapper/multi_property_definition.rb', line 3

def options
  @options
end

#property_nameObject

Returns the value of attribute property_name.



3
4
5
# File 'lib/doc_wrapper/multi_property_definition.rb', line 3

def property_name
  @property_name
end

#selectorsObject

Returns the value of attribute selectors.



3
4
5
# File 'lib/doc_wrapper/multi_property_definition.rb', line 3

def selectors
  @selectors
end

Instance Method Details

#property(documents) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/doc_wrapper/multi_property_definition.rb', line 12

def property (documents)
  results = []
  selectors.each do |selector|
    nodes = documents[@options[:document] - 1].search(selector)
    if nodes.respond_to? :inner_html
      nodes.each do |node|
        results << node.inner_html.strip
      end
    else
      results << nodes.inner_html.strip
    end
  end
  transform(results.flatten)
end

#transform(results) ⇒ Object



27
28
29
30
# File 'lib/doc_wrapper/multi_property_definition.rb', line 27

def transform (results)
  return nil if results.size == 0
  result = block.call(results)
end