Class: DocumentBuilder::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/document_builder/property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type: nil, selector: nil) ⇒ Property

Returns a new instance of Property.



5
6
7
8
9
# File 'lib/document_builder/property.rb', line 5

def initialize(name, type: nil, selector: nil)
  @name = name
  @selector = selector
  @type = type || Coercion::TextProperty
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/document_builder/property.rb', line 3

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



3
4
5
# File 'lib/document_builder/property.rb', line 3

def node
  @node
end

#selectorObject (readonly)

Returns the value of attribute selector.



3
4
5
# File 'lib/document_builder/property.rb', line 3

def selector
  @selector
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/document_builder/property.rb', line 3

def type
  @type
end

Instance Method Details

#call(document) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/document_builder/property.rb', line 11

def call(document)
  return nil if document.nil?

  if selector.nil? || document.name == selector
    @node = document
  else
    @node =  document.at_xpath(selector)
  end

  type.call(@node)
end