Class: DocWrapper::MultiPropertyDefinition
- Inherits:
-
Object
- Object
- DocWrapper::MultiPropertyDefinition
- Defined in:
- lib/doc_wrapper/multi_property_definition.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#options ⇒ Object
Returns the value of attribute options.
-
#property_name ⇒ Object
Returns the value of attribute property_name.
-
#selectors ⇒ Object
Returns the value of attribute selectors.
Instance Method Summary collapse
-
#initialize(property_name, selectors, options, block) ⇒ MultiPropertyDefinition
constructor
A new instance of MultiPropertyDefinition.
- #property(documents) ⇒ Object
- #transform(results) ⇒ Object
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, , block) @property_name = property_name @selectors = selectors @options = @block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
3 4 5 |
# File 'lib/doc_wrapper/multi_property_definition.rb', line 3 def block @block end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/doc_wrapper/multi_property_definition.rb', line 3 def @options end |
#property_name ⇒ Object
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 |
#selectors ⇒ Object
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 |