class Spoll::Response
Attributes
event[RW]
event_type[RW]
event_types[RW]
events[RW]
match[RW]
matches[RW]
team[RW]
teams[RW]
Public Class Methods
new(response)
click to toggle source
# File lib/spoll/response.rb, line 9 def initialize(response) @response = response @matches = [] @events = [] @event_types = [] @teams = [] includes = [ { model: Spoll::Models::Match, key: 'match', attribute: 'match' }, { model: Spoll::Models::Match, key: 'matches', attribute: 'matches' }, { model: Spoll::Models::Event, key: 'events', attribute: 'events' }, { model: Spoll::Models::EventType, key: 'event_types', attribute: 'event_types' }, { model: Spoll::Models::Team, key: 'teams', attribute: 'teams' } ] load_includes(includes) set_relations(includes) end
Public Instance Methods
status()
click to toggle source
# File lib/spoll/response.rb, line 28 def status @response.status end
Private Instance Methods
load_array(attribute, array, model)
click to toggle source
# File lib/spoll/response.rb, line 52 def load_array(attribute, array, model) array.each do |record| send(attribute) << model.new(record) end end
load_include(model, key, attribute)
click to toggle source
# File lib/spoll/response.rb, line 40 def load_include(model, key, attribute) if @response.parsed.key?(key) parsed = @response.parsed[key] if parsed.is_a?(Array) load_array(attribute, parsed, model) else load_single(attribute, parsed, model) end end end
load_includes(includes)
click to toggle source
# File lib/spoll/response.rb, line 34 def load_includes(includes) includes.each do |hash| load_include(hash[:model], hash[:key], hash[:attribute]) end end
load_single(attribute, value, model)
click to toggle source
# File lib/spoll/response.rb, line 58 def load_single(attribute, value, model) self.send("#{attribute}=", model.new(value)) end
set_relations(includes)
click to toggle source
# File lib/spoll/response.rb, line 62 def set_relations(includes) includes.each do |hash| [*hash[:attribute]].each do |record| attribute = send(record) attribute.set_relations(self) if attribute.present? end end end