Class: Infostrada::Team

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/infostrada/team.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}, prefix, &block) ⇒ Team

Returns a new instance of Team.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/infostrada/team.rb', line 26

def initialize(hash = {}, prefix, &block)
  @edition_id = hash['edition_id']

  hash.each do |key, value|
    case key.info_snake_case
    when /^[cn]\w+#{prefix}_?team_id$/
      self.send('team_id=', value)
    when /^[cn]\w+#{prefix}_?team$/
      self.send('team_name=', value)
    when /^[cn]\w+#{prefix}_?team_short$/
      self.send('team_short=', value)
    end
  end
  @nation = Nation.new(hash, "#{prefix}_team")

  block.call(self) if block_given?
  self
end

Instance Attribute Details

#detailsObject

Returns the value of attribute details.



9
10
11
# File 'lib/infostrada/team.rb', line 9

def details
  @details
end

#edition_idObject

Returns the value of attribute edition_id.



9
10
11
# File 'lib/infostrada/team.rb', line 9

def edition_id
  @edition_id
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/infostrada/team.rb', line 9

def id
  @id
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/infostrada/team.rb', line 9

def name
  @name
end

#nationObject

Returns the value of attribute nation.



9
10
11
# File 'lib/infostrada/team.rb', line 9

def nation
  @nation
end

#short_nameObject

Returns the value of attribute short_name.



9
10
11
# File 'lib/infostrada/team.rb', line 9

def short_name
  @short_name
end

Class Method Details

.from_json(json = {}, prefix) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/infostrada/team.rb', line 16

def self.from_json(json = {}, prefix)
  new(prefix) do |team|
    team.id         = json['id']
    team.name       = json['name']
    team.short_name = json['short_name']
    team.nation     = Nation.from_json(json['nation'], "#{prefix}_team") if json['nation']
    team.edition_id = json['edition_id']
  end
end

.where(options = {}) ⇒ Object



11
12
13
14
# File 'lib/infostrada/team.rb', line 11

def self.where(options = {})
  edition_id = options.delete(:edition_id)
  TeamRequest.get_edition(edition_id.to_i)
end

Instance Method Details

#team_id=(id) ⇒ Object



45
46
47
# File 'lib/infostrada/team.rb', line 45

def team_id=(id)
  @id = id
end

#team_name=(name) ⇒ Object



49
50
51
# File 'lib/infostrada/team.rb', line 49

def team_name=(name)
  @name = name
end

#team_short=(short_name) ⇒ Object



53
54
55
# File 'lib/infostrada/team.rb', line 53

def team_short=(short_name)
  @short_name = short_name
end