Class: HasManyPropertyDefinition
- Inherits:
-
Object
- Object
- HasManyPropertyDefinition
- Defined in:
- lib/doc_wrapper/has_many_property_definition.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#options ⇒ Object
Returns the value of attribute options.
-
#property_name ⇒ Object
Returns the value of attribute property_name.
-
#selector ⇒ Object
Returns the value of attribute selector.
Instance Method Summary collapse
- #end_row ⇒ Object
-
#initialize(property_name, selector, klass, options) ⇒ HasManyPropertyDefinition
constructor
A new instance of HasManyPropertyDefinition.
- #property(documents) ⇒ Object
- #start_row ⇒ Object
Constructor Details
#initialize(property_name, selector, klass, options) ⇒ HasManyPropertyDefinition
Returns a new instance of HasManyPropertyDefinition.
5 6 7 8 9 10 |
# File 'lib/doc_wrapper/has_many_property_definition.rb', line 5 def initialize (property_name, selector, klass, ) @property_name = property_name @selector = selector @klass = klass @options = end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
3 4 5 |
# File 'lib/doc_wrapper/has_many_property_definition.rb', line 3 def klass @klass end |
#nodes ⇒ Object
Returns the value of attribute nodes.
3 4 5 |
# File 'lib/doc_wrapper/has_many_property_definition.rb', line 3 def nodes @nodes end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/doc_wrapper/has_many_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/has_many_property_definition.rb', line 3 def property_name @property_name end |
#selector ⇒ Object
Returns the value of attribute selector.
3 4 5 |
# File 'lib/doc_wrapper/has_many_property_definition.rb', line 3 def selector @selector end |
Instance Method Details
#end_row ⇒ Object
29 30 31 |
# File 'lib/doc_wrapper/has_many_property_definition.rb', line 29 def end_row [:end_row] ? [:end_row] : nodes.size - 1 end |
#property(documents) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/doc_wrapper/has_many_property_definition.rb', line 12 def property (documents) self.nodes = documents.collect do |doc| if [:namespaces] result = doc.search(selector, [:namespaces]) else result = doc.search(selector) end result.blank? ? nil : result end.flatten.compact nodes[start_row..end_row].collect { |node| klass.new(node) } end |
#start_row ⇒ Object
25 26 27 |
# File 'lib/doc_wrapper/has_many_property_definition.rb', line 25 def start_row [:start_row] ? [:start_row] : 0 end |