lib/saneitized/hash.rb in saneitized-0.0.1 vs lib/saneitized/hash.rb in saneitized-0.1.0
- old
+ new
@@ -3,40 +3,11 @@
class Hash < SimpleDelegator
def initialize(hash)
super(hash)
hash.each do |key, value|
- next unless value.is_a? String # Only attempt to convert strings
- next if convert_to_true(key, value) # True
- next if convert_to_false(key, value) # False
- next if convert_to_integer(key,value) # Integer
- next if convert_to_float(key, value) # Float
+ hash[key] = Saneitized.convert(value)
end
end
- private
-
- def convert_to_true(key, value)
- (value == 'true' ? self[key] = true : false)
- end
-
- def convert_to_false(key, value)
- (value == 'false' ? (self[key] = false; true) : false)
- end
-
- def convert_to_integer(key, value)
- self[key] = Integer(value)
- true
- rescue ArgumentError, TypeError
- false
- end
-
- def convert_to_float(key, value)
- self[key] = Float(value)
- true
- rescue ArgumentError, TypeError
- false
- end
-
end
-
end