Class: XmlParsable::Elements::NumericElement
- Inherits:
-
AbstractElement
- Object
- AbstractElement
- XmlParsable::Elements::NumericElement
- Defined in:
- lib/xmlparsable/elements/numeric.rb
Overview
Parses content into a ruby Numeric value.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(name, attributes, parent, arguments) ⇒ NumericElement
constructor
A new instance of NumericElement.
- #read(text) ⇒ Object
Methods inherited from AbstractElement
Constructor Details
#initialize(name, attributes, parent, arguments) ⇒ NumericElement
Returns a new instance of NumericElement.
9 10 11 12 |
# File 'lib/xmlparsable/elements/numeric.rb', line 9 def initialize(name, attributes, parent, arguments) @name, @attributes, @parent, @string = name, attributes, parent, "" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/xmlparsable/elements/numeric.rb', line 7 def name @name end |
Instance Method Details
#finalize ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/xmlparsable/elements/numeric.rb', line 18 def finalize stripped = @string.strip numeric = if stripped =~ /[e.]/i and stripped !~ /x/i BigDecimal(stripped) elsif stripped != "" Integer(stripped) end # TODO: Subclass BigDecimal and Integer to add an accessor method numeric.instance_variable_set(:@xmlattrs, @attributes) @parent.close(self, numeric) end |
#read(text) ⇒ Object
14 15 16 |
# File 'lib/xmlparsable/elements/numeric.rb', line 14 def read(text) @string << text end |