lib/xeroizer/report/cell_xml_helper.rb in xeroizer-0.2.0 vs lib/xeroizer/report/cell_xml_helper.rb in xeroizer-0.2.1
- old
+ new
@@ -30,11 +30,11 @@
# }
def build_from_node(node)
cell = new
node.elements.each do | element |
case element.name.to_s
- when 'Value' then cell.value = potentially_convert_to_number(element.text)
+ when 'Value' then cell.value = parse_value(element.text)
when 'Attributes'
element.elements.each do | attribute_node |
(id, value) = parse_attribute(attribute_node)
cell.attributes[id] = value
end
@@ -42,16 +42,19 @@
end
cell
end
protected
-
- # If a cell's value is a valid number then return it is as BigDecimal.
- def potentially_convert_to_number(value)
- value =~ /^[-]?\d+(\.\d+)?$/ ? BigDecimal.new(value) : value
+
+ def parse_value(value)
+ case value
+ when /^[-]?\d+(\.\d+)?$/ then BigDecimal.new(value)
+ when /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/ then Time.xmlschema(value)
+ else value
+ end
end
-
+
def parse_attribute(attribute_node)
id = nil
value = nil
attribute_node.elements.each do | element |
case element.name.to_s
@@ -66,6 +69,6 @@
module InstanceMethods
end
end
end
-end
\ No newline at end of file
+end