Class: FtcEvent::Event
- Inherits:
-
Object
- Object
- FtcEvent::Event
- Defined in:
- lib/ftc_event/event.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #alliance(rank) ⇒ Object
- #code ⇒ Object
- #config ⇒ Object
- #each_phase ⇒ Object
- #each_team ⇒ Object
- #eliminations ⇒ Object
- #end ⇒ Object
-
#initialize(filename) ⇒ Event
constructor
A new instance of Event.
- #league(code = leagues.first) ⇒ Object
- #leagues ⇒ Object
- #name ⇒ Object
- #phases ⇒ Object
- #qualifications ⇒ Object
- #short_name ⇒ Object
- #start ⇒ Object
- #team(number) ⇒ Object
- #teams ⇒ Object
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
#db ⇒ Object (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 |
#code ⇒ Object
25 26 27 |
# File 'lib/ftc_event/event.rb', line 25 def code config['code'] end |
#config ⇒ Object
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_phase ⇒ Object
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_team ⇒ Object
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 |
#eliminations ⇒ Object
71 72 73 |
# File 'lib/ftc_event/event.rb', line 71 def eliminations Eliminations.new(self) end |
#end ⇒ Object
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 |
#leagues ⇒ Object
17 18 19 |
# File 'lib/ftc_event/event.rb', line 17 def leagues db.execute('SELECT code FROM leagueInfo').map { |row| row['code'] } end |
#name ⇒ Object
29 30 31 |
# File 'lib/ftc_event/event.rb', line 29 def name config['name'].gsub(/\s*FTC\s*/, '').strip end |
#phases ⇒ Object
75 76 77 |
# File 'lib/ftc_event/event.rb', line 75 def phases [qualifications, eliminations] end |
#qualifications ⇒ Object
63 64 65 |
# File 'lib/ftc_event/event.rb', line 63 def qualifications Qualifications.new(self) end |
#short_name ⇒ Object
33 34 35 |
# File 'lib/ftc_event/event.rb', line 33 def short_name code.upcase end |
#start ⇒ Object
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 |
#teams ⇒ Object
21 22 23 |
# File 'lib/ftc_event/event.rb', line 21 def teams db.execute('SELECT number FROM teams').map { |row| row['number'] } end |