Class: Sportradar::Api::Mma::Judge

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/mma/judge.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data

Constructor Details

#initialize(data, **opts) ⇒ Judge

Returns a new instance of Judge.



21
22
23
24
25
26
27
28
29
30
# File 'lib/sportradar/api/mma/judge.rb', line 21

def initialize(data, **opts)
  @response = data
  @api      = opts[:api]
  @roster   = opts[:roster]
  @fights_hash = {}

  @id       = data['id']

  update(data)
end

Instance Attribute Details

#first_nameObject

Returns the value of attribute first_name.



5
6
7
# File 'lib/sportradar/api/mma/judge.rb', line 5

def first_name
  @first_name
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/mma/judge.rb', line 5

def id
  @id
end

#last_nameObject

Returns the value of attribute last_name.



5
6
7
# File 'lib/sportradar/api/mma/judge.rb', line 5

def last_name
  @last_name
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/sportradar/api/mma/judge.rb', line 5

def response
  @response
end

Class Method Details

.allObject



17
18
19
# File 'lib/sportradar/api/mma/judge.rb', line 17

def self.all
  @all_hash.values
end

.new(data, **opts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/sportradar/api/mma/judge.rb', line 7

def self.new(data, **opts)
  existing = @all_hash[data['id']]
  if existing
    existing.update(data, **opts)
    existing.add_fight(opts[:fight])
    existing
  else
    @all_hash[data['id']] = super
  end
end

Instance Method Details

#add_fight(fight) ⇒ Object



35
36
37
# File 'lib/sportradar/api/mma/judge.rb', line 35

def add_fight(fight)
  @fights_hash[fight.id] = fight if fight
end

#apiObject



47
48
49
# File 'lib/sportradar/api/mma/judge.rb', line 47

def api
  @api ||= Sportradar::Api::Mma.new
end

#fightsObject



32
33
34
# File 'lib/sportradar/api/mma/judge.rb', line 32

def fights
  @fights_hash.values
end

#update(data, **opts) ⇒ Object



40
41
42
43
44
45
# File 'lib/sportradar/api/mma/judge.rb', line 40

def update(data, **opts)
  @first_name = data['first_name'] if data['first_name'] # "Sai",
  @nick_name  = data['nick_name']  if data['nick_name']  # "The Boss",

  self
end