lib/hashstruct.rb in hashstruct-1.0.0 vs lib/hashstruct.rb in hashstruct-1.0.1
- old
+ new
@@ -1,11 +1,11 @@
require 'date'
require 'uri'
class HashStruct < Hash
- VERSION = '1.0.0'
+ VERSION = '1.0.1'
def initialize(args={})
super()
args.each { |key, value| self[key] = value }
end
@@ -58,20 +58,23 @@
when %r{^-?[\d,]+\.\d+$}
obj.gsub(/,/, '').to_f
# percent
when %r{^-?[\d,]+(\.\d+)?%$}
obj.to_f / 100
+ # rational
+ when %r{^(\d+)/(\d+)$}
+ Rational($1.to_i, $2.to_i)
# date
when %r{^\d{4}-\d{2}-\d{2}}, # 2010-06-06
%r{^\d{1,2}/\d{1,2}/\d{4}}, # 06/06/2010
%r{^\d{4}/\d{1,2}/\d{1,2}}, # 2010/06/06
%r{^(Sun|Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s*\d*\s*\b(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\b} # Sun, 06 Jun 2010 23:02:25 GMT
DateTime.parse(obj)
# boolean true
- when 'true'
+ when 'true', 'yes', 'on'
true
# boolean false
- when 'false'
+ when 'false', 'no', 'off'
false
else
obj
end
when Array