diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-05 13:38:56 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-05 13:38:56 -0700 |
commit | 3d54485fc149b65344db0272df0ed1820bbb03f3 (patch) | |
tree | ebeb95f884ca5ac65d56325974fb35395d284e7b /lib | |
parent | 3027b4d69c2fe2e3f4f254e102af3834fddff2f6 (diff) | |
download | psych-3d54485fc149b65344db0272df0ed1820bbb03f3.zip |
supporting dates
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/scalar_scanner.rb | 2 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb index be1e7b6..5a038a5 100644 --- a/lib/psych/scalar_scanner.rb +++ b/lib/psych/scalar_scanner.rb @@ -12,6 +12,8 @@ module Psych return [:NULL, nil] if @string.empty? case @string + when /^\d{4}-\d{2}-\d{2}$/ + [:DATE, @string] when /^\.inf$/i [:POSITIVE_INFINITY, 1 / 0.0] when /^-\.inf$/i diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 757e27d..da94ebb 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -16,7 +16,15 @@ module Psych return o.value if ['!str', 'tag:yaml.org,2002:str'].include?(o.tag) return o.value if o.quoted - return ScalarScanner.new(o.value).tokenize.last + token = ScalarScanner.new(o.value).tokenize + + case token.first + when :DATE + require 'date' + Date.strptime token.last, '%Y-%m-%d' + else + token.last + end end def visit_Psych_Nodes_Sequence o |