Class: Tweetkit::Response::Resources::Resource

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tweetkit/response.rb

Constant Summary collapse

RESOURCE_NORMALIZATION_KEY =
{
  'users': 'id'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, resource_type) ⇒ Resource

Returns a new instance of Resource.



58
59
60
61
62
63
64
65
66
# File 'lib/tweetkit/response.rb', line 58

def initialize(resource, resource_type)
  @original_resource = resource
  @normalized_resource = {}
  normalization_key = RESOURCE_NORMALIZATION_KEY[resource_type.to_sym]
  resource.each do |data|
    key = data[normalization_key]
    @normalized_resource[key.to_i] = data
  end
end

Instance Attribute Details

#normalized_resourceObject

Returns the value of attribute normalized_resource.



52
53
54
# File 'lib/tweetkit/response.rb', line 52

def normalized_resource
  @normalized_resource
end

#original_resourceObject

Returns the value of attribute original_resource.



52
53
54
# File 'lib/tweetkit/response.rb', line 52

def original_resource
  @original_resource
end

Instance Method Details

#each(*args, &block) ⇒ Object



68
69
70
# File 'lib/tweetkit/response.rb', line 68

def each(*args, &block)
  @normalized_resource.each(*args, &block)
end

#each_data(*args, &block) ⇒ Object



72
73
74
# File 'lib/tweetkit/response.rb', line 72

def each_data(*args, &block)
  @normalized_resource.values.each(*args, &block)
end

#find(key) ⇒ Object



76
77
78
# File 'lib/tweetkit/response.rb', line 76

def find(key)
  @normalized_resource[key.to_i]
end