Class: Termtter::ActiveRubytter

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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ActiveRubytter

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



19
20
21
22
23
24
25
# File 'lib/termtter/active_rubytter.rb', line 19

def method_missing(name, *args)
  if @data.key?(name)
    return @data[name]
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object



15
16
17
# File 'lib/termtter/active_rubytter.rb', line 15

def [](key)
  @data[key]
end

#attributes=(raw_hash) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/termtter/active_rubytter.rb', line 27

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

#idObject



11
12
13
# File 'lib/termtter/active_rubytter.rb', line 11

def id
  @data[:id]
end

#retweeted_statusObject



47
48
49
# File 'lib/termtter/active_rubytter.rb', line 47

def retweeted_status
  nil
end

#to_hashObject



39
40
41
42
43
44
45
# File 'lib/termtter/active_rubytter.rb', line 39

def to_hash
  @data.inject({}) do |memo, (key, value)|
    memo[key] =
      (value.kind_of? self.class) ? value.to_hash : value
    memo
  end
end