Class: F1Results::Event
- Inherits:
-
Object
- Object
- F1Results::Event
- Defined in:
- lib/f1results/event.rb
Instance Attribute Summary collapse
-
#circuit ⇒ Object
Returns the value of attribute circuit.
-
#grand_prix ⇒ Object
Returns the value of attribute grand_prix.
-
#name ⇒ Object
Returns the value of attribute name.
-
#results ⇒ Object
Returns the value of attribute results.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
Returns the value of attribute url.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #get_results ⇒ Object
- #get_results_with_url(url) ⇒ Object
- #grand_prix_slug ⇒ Object
-
#initialize(args = {}) ⇒ Event
constructor
A new instance of Event.
- #losing ⇒ Object
- #practice1? ⇒ Boolean
- #practice2? ⇒ Boolean
- #practice3? ⇒ Boolean
- #practice? ⇒ Boolean
- #qualifying? ⇒ Boolean
- #race? ⇒ Boolean
- #to_a ⇒ Object
-
#type_name ⇒ Object
Human readable type, e.g.
- #winning ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Event
Returns a new instance of Event.
5 6 7 8 |
# File 'lib/f1results/event.rb', line 5 def initialize(args = {}) @results = [] args.each { |k,v| send("#{k}=", v) } end |
Instance Attribute Details
#circuit ⇒ Object
Returns the value of attribute circuit.
3 4 5 |
# File 'lib/f1results/event.rb', line 3 def circuit @circuit end |
#grand_prix ⇒ Object
Returns the value of attribute grand_prix.
3 4 5 |
# File 'lib/f1results/event.rb', line 3 def grand_prix @grand_prix end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/f1results/event.rb', line 3 def name @name end |
#results ⇒ Object
Returns the value of attribute results.
3 4 5 |
# File 'lib/f1results/event.rb', line 3 def results @results end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/f1results/event.rb', line 3 def type @type end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/f1results/event.rb', line 3 def url @url end |
#year ⇒ Object
Returns the value of attribute year.
3 4 5 |
# File 'lib/f1results/event.rb', line 3 def year @year end |
Instance Method Details
#[](i) ⇒ Object
52 53 54 |
# File 'lib/f1results/event.rb', line 52 def [](i) @results[i] end |
#get_results ⇒ Object
64 65 66 67 |
# File 'lib/f1results/event.rb', line 64 def get_results agent = F1Results::Agent.new agent.get_results(self) end |
#get_results_with_url(url) ⇒ Object
69 70 71 72 |
# File 'lib/f1results/event.rb', line 69 def get_results_with_url(url) agent = F1Results::Agent.new agent.fetch_results_with_url(url) end |
#grand_prix_slug ⇒ Object
10 11 12 |
# File 'lib/f1results/event.rb', line 10 def grand_prix_slug grand_prix.strip.downcase.gsub(/[:space:]+/, '-') end |
#losing ⇒ Object
60 61 62 |
# File 'lib/f1results/event.rb', line 60 def losing self[-1] end |
#practice1? ⇒ Boolean
28 29 30 |
# File 'lib/f1results/event.rb', line 28 def practice1? @type == :practice1 end |
#practice2? ⇒ Boolean
32 33 34 |
# File 'lib/f1results/event.rb', line 32 def practice2? @type == :practice2 end |
#practice3? ⇒ Boolean
36 37 38 |
# File 'lib/f1results/event.rb', line 36 def practice3? @type == :practice3 end |
#practice? ⇒ Boolean
24 25 26 |
# File 'lib/f1results/event.rb', line 24 def practice? /^practice(1|2|3)$/ =~ @type.to_s end |
#qualifying? ⇒ Boolean
40 41 42 |
# File 'lib/f1results/event.rb', line 40 def @type == :qualifying end |
#race? ⇒ Boolean
44 45 46 |
# File 'lib/f1results/event.rb', line 44 def race? @type == :race end |
#to_a ⇒ Object
48 49 50 |
# File 'lib/f1results/event.rb', line 48 def to_a @results.map(&:to_a) end |
#type_name ⇒ Object
Human readable type, e.g. "Practice 1", "Qualifying", "Starting Grid"
15 16 17 18 19 20 21 22 |
# File 'lib/f1results/event.rb', line 15 def type_name @type.to_s .gsub(/\d/, ' \0') .gsub('_', ' ') .split(' ') .map(&:capitalize) .join(' ') end |
#winning ⇒ Object
56 57 58 |
# File 'lib/f1results/event.rb', line 56 def winning self[0] end |