Class: HasOnePropertyDefinition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property_name, selector, klass, options) ⇒ HasOnePropertyDefinition

Returns a new instance of HasOnePropertyDefinition.



5
6
7
8
9
10
# File 'lib/doc_wrapper/has_one_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_one_property_definition.rb', line 3

def klass
  @klass
end

#optionsObject

Returns the value of attribute options.



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

def selector
  @selector
end

Instance Method Details

#property(documents) ⇒ Object



12
13
14
15
# File 'lib/doc_wrapper/has_one_property_definition.rb', line 12

def property (documents)
  nodes = documents.collect { |doc| result = doc.search(selector) ; result.blank? ? nil : result }.flatten.compact
  klass.new(nodes)
end