Class: Termtter::ActiveRubytter
- Inherits:
-
Object
- Object
- Termtter::ActiveRubytter
show all
- Defined in:
- lib/termtter/active_rubytter.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ActiveRubytter.
7
8
9
|
# File 'lib/termtter/active_rubytter.rb', line 7
def initialize(data)
self.attributes = data
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/termtter/active_rubytter.rb', line 11
def method_missing(name, *args)
if @data.key?(name)
return @data[name]
else
super
end
end
|
Instance Method Details
#attributes=(raw_hash) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/termtter/active_rubytter.rb', line 19
def attributes=(raw_hash)
@data = {}
raw_hash.each do |key, value|
key_symbol = key.to_s.to_sym
if value.kind_of? Hash
@data[key_symbol] = ActiveRubytter.new(raw_hash[key])
else
@data[key_symbol] = raw_hash[key]
end
end
end
|
#to_hash ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/termtter/active_rubytter.rb', line 31
def to_hash
@data.inject({}) do |memo, (key, value)|
memo[key] =
(value.kind_of? self.class) ? value.to_hash : value
memo
end
end
|