Class: Trubl::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/trubl/collection.rb

Direct Known Subclasses

Authorizations, Hashtags, Touts, Users, Widgets

Instance Method Summary collapse

Instance Method Details

#container_nameObject



16
17
18
# File 'lib/trubl/collection.rb', line 16

def container_name
  klass_name
end

#from_response(response, options = {}) ⇒ Object



6
7
8
9
10
# File 'lib/trubl/collection.rb', line 6

def from_response(response, options = {})
  return nil if missing_or_exception?(response)
  json = JSON.parse(response.body)
  self.concat (json[container_name] || []).map{|m| klass.new(m[member_name]) }
end

#klassObject



12
13
14
# File 'lib/trubl/collection.rb', line 12

def klass
  "Trubl::#{member_name.classify}".constantize
end

#klass_nameObject



24
25
26
# File 'lib/trubl/collection.rb', line 24

def klass_name
  self.class.name.downcase.gsub('trubl::', '')
end

#member_nameObject



20
21
22
# File 'lib/trubl/collection.rb', line 20

def member_name
  klass_name.singularize
end