Module: XMLObject::String
- Defined in:
- lib/xml-object/string.rb
Instance Method Summary collapse
-
#blank? ⇒ Boolean
A decorated String is blank when it has a blank value, no child elements, and no attributes.
-
#rb ⇒ Object
Attempts to detect wether this String is really an integer or float, and returns accordingly.
Instance Method Details
#blank? ⇒ Boolean
A decorated String is blank when it has a blank value, no child elements, and no attributes. For example:
<blank_element></blank_element>
21 22 23 |
# File 'lib/xml-object/string.rb', line 21 def blank? (self !~ /\S/) && @__children.blank? && @__attributes.blank? end |
#rb ⇒ Object
Attempts to detect wether this String is really an integer or float, and returns accordingly. If not, just returns the string.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/xml-object/string.rb', line 5 def rb result = case when (self !~ /\S/) then '' when match(/[a-zA-Z]/) then ::String.new(self) when match(/^[+-]?\d+$/) then self.to_i when match(/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/) then self.to_f else ::String.new(self) end @__rb ||= result end |