Class: FtcEvent::Alliance

Inherits:
Object
  • Object
show all
Defined in:
lib/ftc_event/alliance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, rank) ⇒ Alliance

Returns a new instance of Alliance.



8
9
10
11
# File 'lib/ftc_event/alliance.rb', line 8

def initialize(event, rank)
  @event = event
  @rank = rank
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



5
6
7
# File 'lib/ftc_event/alliance.rb', line 5

def event
  @event
end

#rankObject (readonly)

Returns the value of attribute rank.



6
7
8
# File 'lib/ftc_event/alliance.rb', line 6

def rank
  @rank
end

Instance Method Details

#each_teamObject



21
22
23
24
25
26
27
28
29
# File 'lib/ftc_event/alliance.rb', line 21

def each_team
  return enum_for(:each_team) unless block_given?

  teams.each do |team_number|
    yield event.team(team_number)
  end

  nil
end

#infoObject



13
14
15
# File 'lib/ftc_event/alliance.rb', line 13

def info
  event.db.query('SELECT * FROM alliances WHERE rank = ?', [rank])&.first
end

#long_descriptionObject



43
44
45
# File 'lib/ftc_event/alliance.rb', line 43

def long_description
  "##{rank} #{long_team_list}"
end

#long_team_listObject



35
36
37
# File 'lib/ftc_event/alliance.rb', line 35

def long_team_list
  each_team.map(&:description).join(' and ')
end

#short_descriptionObject



39
40
41
# File 'lib/ftc_event/alliance.rb', line 39

def short_description
  "##{rank} #{short_team_list}"
end

#short_team_listObject



31
32
33
# File 'lib/ftc_event/alliance.rb', line 31

def short_team_list
  each_team.map(&:number).join('/')
end

#teamsObject



17
18
19
# File 'lib/ftc_event/alliance.rb', line 17

def teams
  [1, 2, 3].map { |n| info["team#{n}"] }.reject(&:zero?)
end