Class: FAP::Property
- Inherits:
-
Object
- Object
- FAP::Property
- Defined in:
- lib/fap/property.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#xpath ⇒ Object
readonly
Returns the value of attribute xpath.
Instance Method Summary collapse
-
#cast(node) ⇒ Object
Cast a Nokogiri node value to @type.
-
#initialize(name, opt = {}) ⇒ Property
constructor
A new instance of Property.
Constructor Details
#initialize(name, opt = {}) ⇒ Property
Returns a new instance of Property.
5 6 7 8 9 10 |
# File 'lib/fap/property.rb', line 5 def initialize name, opt={} @name = name @type = opt[:type] || 'String' @xpath = opt[:xpath] || name.to_s @attribute = opt[:get] || nil end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
3 4 5 |
# File 'lib/fap/property.rb', line 3 def attribute @attribute end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/fap/property.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/fap/property.rb', line 3 def type @type end |
#xpath ⇒ Object (readonly)
Returns the value of attribute xpath.
3 4 5 |
# File 'lib/fap/property.rb', line 3 def xpath @xpath end |
Instance Method Details
#cast(node) ⇒ Object
Cast a Nokogiri node value to @type
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fap/property.rb', line 16 def cast node raise "Invalid XML node" if node.nil? what = @attribute ? node[@attribute.to_s] : node.text case @type when 'Fixnum' what.to_i 10 when 'DateTime' DateTime.parse what when 'URI' URI.parse what when 'String' what.to_s else FAP.constantize(@type).new(what) end end |