Class: FtcEvent::Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Event

Returns a new instance of Event.



7
8
9
# File 'lib/ftc_event/event.rb', line 7

def initialize(filename)
  @db = SQLite3::Database.new(filename, results_as_hash: true)
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



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

def db
  @db
end

Instance Method Details

#alliance(rank) ⇒ Object



67
68
69
# File 'lib/ftc_event/event.rb', line 67

def alliance(rank)
  Alliance.new(self, rank)
end

#codeObject



25
26
27
# File 'lib/ftc_event/event.rb', line 25

def code
  config['code']
end

#configObject



11
12
13
14
15
# File 'lib/ftc_event/event.rb', line 11

def config
  db.execute('SELECT key, value FROM config').each_with_object({}) do |row, h|
    h[row['key']] = row['value']
  end
end

#each_phaseObject



79
80
81
82
83
84
85
86
87
# File 'lib/ftc_event/event.rb', line 79

def each_phase
  return enum_for(:each_phase) unless block_given?

  phases.each do |phase|
    yield phase unless phase.matches.empty?
  end

  nil
end

#each_teamObject



53
54
55
56
57
58
59
60
61
# File 'lib/ftc_event/event.rb', line 53

def each_team
  return enum_for(:each_team) unless block_given?

  teams.each do |number|
    yield team(number)
  end

  nil
end

#eliminationsObject



71
72
73
# File 'lib/ftc_event/event.rb', line 71

def eliminations
  Eliminations.new(self)
end

#endObject



41
42
43
# File 'lib/ftc_event/event.rb', line 41

def end
  Time.at(config['end'].to_f / 1000.0)
end

#league(code = leagues.first) ⇒ Object



45
46
47
# File 'lib/ftc_event/event.rb', line 45

def league(code = leagues.first)
  League.new(self, code) if code
end

#leaguesObject



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

def leagues
  db.execute('SELECT code FROM leagueInfo').map { |row| row['code'] }
end

#nameObject



29
30
31
# File 'lib/ftc_event/event.rb', line 29

def name
  config['name'].gsub(/\s*FTC\s*/, '').strip
end

#phasesObject



75
76
77
# File 'lib/ftc_event/event.rb', line 75

def phases
  [qualifications, eliminations]
end

#qualificationsObject



63
64
65
# File 'lib/ftc_event/event.rb', line 63

def qualifications
  Qualifications.new(self)
end

#short_nameObject



33
34
35
# File 'lib/ftc_event/event.rb', line 33

def short_name
  code.upcase
end

#startObject



37
38
39
# File 'lib/ftc_event/event.rb', line 37

def start
  Time.at(config['start'].to_f / 1000.0)
end

#team(number) ⇒ Object



49
50
51
# File 'lib/ftc_event/event.rb', line 49

def team(number)
  Team.new(self, number)
end

#teamsObject



21
22
23
# File 'lib/ftc_event/event.rb', line 21

def teams
  db.execute('SELECT number FROM teams').map { |row| row['number'] }
end