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.
8
9
10
|
# File 'lib/termtter/active_rubytter.rb', line 8
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
20
21
22
|
# File 'lib/termtter/active_rubytter.rb', line 20
def method_missing(name, *args)
@data[name]
end
|
Instance Method Details
#[](key) ⇒ Object
16
17
18
|
# File 'lib/termtter/active_rubytter.rb', line 16
def [](key)
@data[key]
end
|
#attributes=(raw_hash) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/termtter/active_rubytter.rb', line 24
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
|
#destructize ⇒ Object
44
45
46
|
# File 'lib/termtter/active_rubytter.rb', line 44
def destructize
self.to_hash
end
|
#id ⇒ Object
12
13
14
|
# File 'lib/termtter/active_rubytter.rb', line 12
def id
@data[:id]
end
|
48
49
50
|
# File 'lib/termtter/active_rubytter.rb', line 48
def
nil
end
|
#to_hash ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/termtter/active_rubytter.rb', line 36
def to_hash
@data.inject({}) do |memo, (key, value)|
memo[key] =
(value.kind_of? self.class) ? value.to_hash : value
memo
end
end
|