Class: Atig::TwitterStruct

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

Overview

from tig.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ TwitterStruct

Returns a new instance of TwitterStruct.



22
23
24
# File 'lib/atig/twitter_struct.rb', line 22

def initialize(obj)
  @obj = obj
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



58
59
60
61
# File 'lib/atig/twitter_struct.rb', line 58

def method_missing(sym, *args)
  # XXX
  @obj[sym.to_s]
end

Class Method Details

.make(obj) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/atig/twitter_struct.rb', line 7

def self.make(obj)
  case obj
  when Hash
    obj = obj.dup
    obj.each do |k, v|
      obj[k] = TwitterStruct.make(v)
    end
    TwitterStruct.new(obj)
  when Array
    obj.map {|i| TwitterStruct.make(i) }
  else
    obj
  end
end

Instance Method Details

#==(other) ⇒ Object



54
55
56
# File 'lib/atig/twitter_struct.rb', line 54

def ==(other)
  self.hash == other.hash
end

#[](name) ⇒ Object



30
31
32
# File 'lib/atig/twitter_struct.rb', line 30

def [](name)
  @obj[name.to_s]
end

#[]=(name, val) ⇒ Object



34
35
36
# File 'lib/atig/twitter_struct.rb', line 34

def []=(name,val)
  @obj[name.to_s] = val
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/atig/twitter_struct.rb', line 50

def eql?(other)
  self.hash == other.hash
end

#hashObject



46
47
48
# File 'lib/atig/twitter_struct.rb', line 46

def hash
  self.id ? self.id.hash : super
end

#idObject



26
27
28
# File 'lib/atig/twitter_struct.rb', line 26

def id
  @obj["id"]
end

#merge(hash) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/atig/twitter_struct.rb', line 38

def merge(hash)
  obj = @obj.dup
  hash.each do|key,value|
    obj[key.to_s] = value
  end
  TwitterStruct.make obj
end