Class: InfomemeClient::EntityHash
- Inherits:
-
Object
- Object
- InfomemeClient::EntityHash
show all
- Defined in:
- lib/infomeme_client/entity_hash.rb
Defined Under Namespace
Classes: Comment, Invoice, Meme, MemeType, Report, Review, Transaction, User
Instance Method Summary
collapse
Constructor Details
#initialize(hsh, no_freeze = false) ⇒ EntityHash
Returns a new instance of EntityHash.
11
12
13
14
15
16
17
18
|
# File 'lib/infomeme_client/entity_hash.rb', line 11
def initialize(hsh, no_freeze = false)
@hsh = hsh.inject({}) {|memo, keyvalue| key, value = keyvalue
memo[(key.to_sym rescue key) || key] = map_values(value)
memo
}
freeze unless no_freeze
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym) ⇒ Object
20
21
22
|
# File 'lib/infomeme_client/entity_hash.rb', line 20
def method_missing(sym)
@hsh.key?(sym) ? @hsh[sym] : super
end
|
Instance Method Details
#freeze ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/infomeme_client/entity_hash.rb', line 35
def freeze
@hsh.each do |key, val|
deep_freeze(val)
end
@hsh.freeze
super
end
|
#id ⇒ Object
43
44
45
|
# File 'lib/infomeme_client/entity_hash.rb', line 43
def id
@hsh.key?(:id) ? @hsh[:id] : super
end
|
#respond_to?(sym, include_private = false) ⇒ Boolean
24
25
26
|
# File 'lib/infomeme_client/entity_hash.rb', line 24
def respond_to?(sym, include_private = false)
@hsh.key?(sym) ? true : super
end
|
#to_hash ⇒ Object
28
29
30
31
32
33
|
# File 'lib/infomeme_client/entity_hash.rb', line 28
def to_hash
@hsh.inject({}) do |memo, (key, value)|
memo[key] = (value)
memo
end
end
|