Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for Time values.

  • Loading branch information...
commit ec15c01e6dc1b4a95a78e99eb67e9a78a1d1d904 1 parent 5eda76e
@tylerhunt authored
Showing with 6 additions and 0 deletions.
  1. +3 −0  lib/relief/element.rb
  2. +3 −0  spec/parser_spec.rb
View
3  lib/relief/element.rb
@@ -1,3 +1,5 @@
+require 'time'
+
module Relief
class Element
attr_reader :name, :options, :children
@@ -29,6 +31,7 @@ def parse(document)
elsif type == Integer then value.to_i
elsif type == Float then value.to_f
elsif type == Date then Date.parse(value)
+ elsif type == Time then Time.parse(value)
elsif type == DateTime then DateTime.parse(value)
elsif type.is_a?(Parser) then type.parse(document)
else value
View
3  spec/parser_spec.rb
@@ -129,6 +129,7 @@
element :id, :type => Integer
element :rating, :type => Float
element :taken, :type => Date
+ element :modified, :type => Time
element :published, :type => DateTime
end
@@ -138,6 +139,7 @@
<id>86634</id>
<rating>3.5</rating>
<taken>2009-05-06</taken>
+ <modified>2009-05-08T18:23:48-07:00</modified>
<published>2009-05-08T18:23:26-07:00</published>
</photo>
XML
@@ -146,6 +148,7 @@
:id => 86634,
:rating => 3.5,
:taken => Date.new(2009, 5, 6),
+ :modified => Time.parse('2009-05-08T18:23:48-07:00'),
:published => DateTime.new(2009, 5, 8, 18, 23, 26, Date.time_to_day_fraction(-7, 0, 0))
}
end
Please sign in to comment.
Something went wrong with that request. Please try again.