Class: HasManyPropertyDefinition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @property_name = property_name
  @selector = selector
  @klass = klass
  @options = options
end

Instance Attribute Details

#klassObject

Returns the value of attribute klass.



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

def klass
  @klass
end

#nodesObject

Returns the value of attribute nodes.



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

def nodes
  @nodes
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/doc_wrapper/has_many_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/has_many_property_definition.rb', line 3

def property_name
  @property_name
end

#selectorObject

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_rowObject



29
30
31
# File 'lib/doc_wrapper/has_many_property_definition.rb', line 29

def end_row
  options[:end_row] ? options[: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 options[:namespaces]
      result = doc.search(selector, options[: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_rowObject



25
26
27
# File 'lib/doc_wrapper/has_many_property_definition.rb', line 25

def start_row
  options[:start_row] ? options[:start_row] : 0
end