Class: H20::H2o

Inherits:
Object
  • Object
show all
Defined in:
lib/h20.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ H2o

Returns a new instance of H2o.



5
6
7
8
9
10
11
12
# File 'lib/h20.rb', line 5

def initialize(params)
  if params.kind_of?(Hash)
    @attributes = params #.deep_symbolize_keys
    # hash_to_methods
  else
    @attributes = params
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/h20.rb', line 22

def method_missing(m)
	if @attributes.map{|k,v| k}.include?(m)
 	value = @attributes[m]
 	r_value = nil
 	if value.kind_of?(Hash)
 		r_value = H2o.new(value)
 	elsif value.kind_of?(Array)
 		r_value = value.map { |e| H2o.new(e)  }
 	else
 		r_value = value
 	end
 	r_value
 else
 	super
 end
end

Instance Method Details

#to_hashObject



18
19
20
# File 'lib/h20.rb', line 18

def to_hash
  @attributes
end

#to_jsonObject



14
15
16
# File 'lib/h20.rb', line 14

def to_json
  @attributes.to_json
end