Module: MODL::Model
- Defined in:
- lib/modl/model/model.rb
Overview
A Model module for MODL
Defined Under Namespace
Classes: Modl, ModlArray, ModlBoolNull, ModlFloat, ModlInteger, ModlMap, ModlPair, ModlPrimitive, ModlQuoted, ModlString
Class Method Summary collapse
-
.to_modl(obj) ⇒ Object
Convert a Ruby Hash/Array/Primitive to a Modl object.
Class Method Details
.to_modl(obj) ⇒ Object
Convert a Ruby Hash/Array/Primitive to a Modl object.
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/modl/model/model.rb', line 236 def self.to_modl(obj) if obj.instance_of? Float ModlFloat.new obj elsif obj.instance_of? Integer ModlInteger.new obj elsif obj.instance_of? String ModlString.new obj elsif obj.instance_of? Hash if obj.keys.length == 1 key = obj.keys[0] ModlPair.new key, to_modl(obj[key]) else ModlMap.new(obj.keys.map { |k| ModlPair.new k, to_modl(obj[k]) }) end elsif obj.instance_of? Array ModlArray.new(obj.map { |i| to_modl i }) elsif obj.instance_of? TrueClass ModlBoolNull::MODL_TRUE elsif obj.instance_of? FalseClass ModlBoolNull::MODL_FALSE elsif obj.instance_of? NilClass ModlBoolNull::MODL_NULL else puts "Cannot handle #{obj}" exit end end |