ODM
Simple Object Data Mapper
Parse Array of Hash into random Class of classes to make it more object oriented on the fly :)
at this point the following classes (and they child's) are implemented:
- [ Module, Array, Hash, Regexp, String, File, IO ]
initialize method will be called directly in array and hash classes, but will be exception handled if Argument or NoMethod Error occurs
example
require 'odm'
#> some random class as target models
class STRING < String
end
class ARRAY < Array
end
class HASH < Hash
def initialize original_obj
# some stuff on init for fun
end
end
odm= ODM.new do |opts|
opts.array = ARRAY
opts.hash = HASH
opts.string = STRING
end
var= odm.parse [ {hello: {"world" => "hey!"} }, 123 ]
puts var.inspect,var.class,var[0].class,var[0][:hello].keys[0].class
#> [{:hello=>{"world"=>"hey!"}}, 123], ARRAY, HASH, STRING
yaml and json can be parsed too
require 'yaml'
yaml_data= [ {hello: {"world" => "hey!"} }, 123 ].to_yaml
puts odm.parse_yml(yaml_data).inspect
#> [{:hello=>{"world"=>"hey!"}}, 123]