lib/hooloo/mozart_hash.rb in hooloo-0.2.0 vs lib/hooloo/mozart_hash.rb in hooloo-0.2.1
- old
+ new
@@ -19,9 +19,19 @@
def bool(*mappings)
field_mapping(mappings).each do |field, mapping|
define_method(field.to_s + '?') { @obj[mapping] }
end
end
+ def uri(*mappings)
+ field_mapping(mappings).each do |field, mapping|
+ define_method(field.to_s) { URI @obj[mapping.to_s] }
+ end
+ end
+ def float(*mappings)
+ field_mapping(mappings).each do |field, mapping|
+ define_method(field.to_s) { @obj[mapping.to_s].to_f }
+ end
+ end
def cast(klass, mappings, opts={map_array: true, map: false})
field_mapping(mappings).each do |field, mapping|
define_method(field) do
if opts[:map] || (@obj[mapping].is_a?(Array) && opts[:map_array])
@obj[mapping].map { |x| klass.new(x) }