Class: DocumentBuilder::Property
- Inherits:
-
Object
- Object
- DocumentBuilder::Property
- Defined in:
- lib/document_builder/property.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #call(document) ⇒ Object
-
#initialize(name, type: nil, selector: nil) ⇒ Property
constructor
A new instance of Property.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/document_builder/property.rb', line 3 def name @name end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
3 4 5 |
# File 'lib/document_builder/property.rb', line 3 def node @node end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
3 4 5 |
# File 'lib/document_builder/property.rb', line 3 def selector @selector end |
#type ⇒ Object (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 |