Class: XmlParsable::Elements::NumericElement

Inherits:
AbstractElement show all
Defined in:
lib/xmlparsable/elements/numeric.rb

Overview

Parses content into a ruby Numeric value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractElement

#comment, #open, parsable

Constructor Details

#initialize(name, attributes, parent, *arguments) ⇒ NumericElement

Returns a new instance of NumericElement.



9
10
11
# File 'lib/xmlparsable/elements/numeric.rb', line 9

def initialize(name, attributes, parent, *arguments)
  @name, @parent, @string = name, parent, ""
end

Instance Attribute Details

#nameObject (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

#finalizeObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/xmlparsable/elements/numeric.rb', line 17

def finalize
  stripped = @string.strip
  numeric  = if stripped =~ /[e.]/i and stripped !~ /x/i
               BigDecimal(stripped)
             elsif stripped != ""
               Integer(stripped)
             end

  @parent.close(self, numeric)
end

#read(text) ⇒ Object



13
14
15
# File 'lib/xmlparsable/elements/numeric.rb', line 13

def read(text)
  @string << text
end