f1results 0.2.pre.alpha.3 → 0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c381557affdd5f2d9ce7294b915df1120a78a04f
4
- data.tar.gz: 067d5b07bae14ce0c051997d0668cf5d69fe85b3
3
+ metadata.gz: 1b051ec7bbb7427df68b608f368ec9da378563ad
4
+ data.tar.gz: 7e0c83eaae83f0f033c0bd6137819b6d9f2e5fed
5
5
  SHA512:
6
- metadata.gz: 7cec638c906397d24bfdfa57162387c800ad1fa571c83e6944d16feaca4885c5675aaa4f39ab5efde1b0b541265aa39230bd044e8a484a09094eaba2c6af09b1
7
- data.tar.gz: e844bd99064029f4c3ac02f1c25580462f4726a410df61c5e7e86bc9a1a5d88b95a4a098b978e8b90646ab5bd05647aa57d98fcc07ee3461eace8c91e02f837c
6
+ metadata.gz: 81e62187f6284f0a4449a31ca52e676b390e1dbb1ecbe946074f1020b139be6f628a2caee888582ec18ebb2ba0fb959ccbeff78a1adcd24a1c1565e76a046a32
7
+ data.tar.gz: b69492c988f8047988587a10097f0577ea3be5b8a19b6e3614249040f6917e3e092120361e97d848be6ffa0e2169153df71ff702d54d73882588e1e5ef0feb7d
data/README.md CHANGED
@@ -22,4 +22,4 @@ Or install it yourself as:
22
22
 
23
23
  ### Command Line
24
24
 
25
- $ f1results <season> [<round>] [-q, --qualifying]
25
+ $ f1results -y <year> -c <country> [-e p1|p2|p3|q|r]
data/bin/f1results CHANGED
@@ -8,33 +8,41 @@ require File.expand_path('../../lib/f1results.rb', __FILE__)
8
8
  year = Time.now.year
9
9
  country = ''
10
10
  event_type = :race
11
+ url = nil
11
12
 
12
13
  optparse = OptionParser.new do |opts|
13
14
  opts.on('-y', '--year=YEAR', Integer) { |val| year = val }
14
15
  opts.on('-c', '--country=COUNTRY', String) { |val| country = val.downcase }
15
16
  opts.on('-e', '--event=EVENT', String) { |val| event_type = val.downcase.to_sym }
17
+ opts.on('-u', '--url=URL', String) { |val| url = val }
16
18
  opts.parse!
17
19
  end
18
20
 
19
21
  begin
20
- event = F1Results.get(year, country, event_type)
21
- rescue Exception => e
22
- puts e
22
+ event = if url.nil?
23
+ F1Results.fetch(year, country, event_type)
24
+ else
25
+ F1Results.fetch_with_url(url)
26
+ end
27
+ rescue
28
+ event_summary = url || "#{year} #{country} #{event_type}"
29
+ puts "No results for #{event_summary}"
23
30
  exit
24
31
  end
25
32
 
26
- title = "#{event.season} #{event.country} #{event.type_name}\n#{event.name}"
33
+ title = url.nil? ? "#{event.year} #{event.country_name} #{event.type_name}\n#{event.name}" : event.name
27
34
  table = Terminal::Table.new title: title, rows: event.to_a
28
35
 
29
36
  if event.practice?
30
- table.headings = %W(Pos Driver Team Time Laps)
37
+ table.headings = %W(Pos Num Driver Team Time Gap Laps)
31
38
  table.align_column 0, :right
39
+ table.align_column 1, :right
32
40
  table.align_column 4, :right
41
+ table.align_column 6, :right
33
42
 
34
43
  elsif event.qualifying?
35
44
  table.headings = %W(Pos Driver Team Q1 Q2 Q3 Laps)
36
45
  table.align_column 0, :right
37
- table.align_column 1, :right
38
46
  table.align_column 6, :right
39
47
 
40
48
  elsif event.race?
@@ -2,20 +2,103 @@ require 'mechanize'
2
2
 
3
3
  module F1Results
4
4
  class Agent < ::Mechanize
5
- def get_event(season, country, type)
6
- event = Event.new(season: season, country: country, type: type)
7
- path = "content/fom-website/en/championship/results/#{season}-race-results/#{season}-#{event.country_slug}-results/#{event.type_slug}.html"
5
+ attr_accessor :event
8
6
 
7
+ def initialize(event = nil)
8
+ if event.nil?
9
+ @event = F1Results::Event.new
10
+ else
11
+ self.event = event
12
+ end
13
+ super
14
+ end
15
+
16
+ def fetch_results
17
+ return fetch_results_with_url(@default_url)
18
+ end
19
+
20
+ def fetch_results_with_url(url)
9
21
  begin
10
- get(::File.join(F1Results::BASEURL, path))
22
+ get(url)
23
+ @event.type = parse_event_type if @event.type.nil?
24
+ @event.country = parse_event_country if @event.country.nil?
25
+ @event.name = parse_event_title
26
+ @event.results = parse_event_results
27
+ return @event
11
28
  rescue Mechanize::ResponseCodeError, Net::HTTPNotFound
12
- raise 'No results'
29
+ raise "No results found at #{url}"
13
30
  end
31
+ end
14
32
 
15
- event.name = page.parser.xpath('//a[contains(@class, "level-0")]').text
16
- table = page.parser.xpath('//tbody')
17
-
18
- return event.parse_results_table(table)
33
+ def event=(event)
34
+ path = "content/fom-website/en/championship/results/#{event.year}-race-results/#{event.year}-#{event.country_slug}-results/#{event.type_slug}.html"
35
+ @default_url = ::File.join F1Results::BASEURL, path
36
+ @event = event
19
37
  end
38
+
39
+ private
40
+
41
+ def parse_event_type
42
+ return page.parser.xpath('//h1[@class="headline"]').text.strip rescue nil
43
+ end
44
+
45
+ def parse_event_country
46
+ return page.parser.xpath('//a[@class="tag-link"]').text.strip.parameterize rescue nil
47
+ end
48
+
49
+ def parse_event_title
50
+ return page.parser.xpath('//a[contains(@class, "level-0")]').text rescue nil
51
+ end
52
+
53
+ def parse_event_results
54
+ results = []
55
+ table = page.parser.xpath('//tbody')
56
+
57
+ # Remove driver abbreviation from cell
58
+ table.xpath('//span[@class="tla"]').each(&:remove)
59
+
60
+ # Turn HTML table into an array of arrays
61
+ data = table.xpath('//tr').map do |row|
62
+ row.xpath('./td|./th').map do |cell|
63
+ cell = cell.text.gsub(/[[:space:]]+/, ' ').strip
64
+ cell.blank? ? nil : cell
65
+ end
66
+ end
67
+
68
+ # Remove rows that have the cell "Q1 107% Time"
69
+ regex = /107%/
70
+ data.reject! { |row| row.any? { |cell| regex =~ cell } }
71
+
72
+ header = parse_table_header(data.shift)
73
+
74
+ result_class = case
75
+ when @event.practice?
76
+ PracticeResult
77
+ when @event.qualifying?
78
+ QualifyingResult
79
+ else
80
+ RaceResult
81
+ end
82
+
83
+ data.each_with_index do |row, i|
84
+ hash = Hash[header.zip(row)]
85
+ hash[:index] = i
86
+
87
+ result = result_class.new(hash)
88
+ results << result
89
+ end
90
+
91
+ return results
92
+ end
93
+
94
+ # Turn array of words to symbols
95
+ def parse_table_header(header)
96
+ header.map do |cell|
97
+ # Fix i18n cells that look like this
98
+ # {'Position' @ i18n}, {'Driver' @ i18n}, ...
99
+ cell = cell.match(/(')(.+)(')/)[2] if /i18n/ =~ cell
100
+ cell.to_s.strip.parameterize('_').to_sym
101
+ end
102
+ end
20
103
  end
21
104
  end
@@ -2,9 +2,9 @@ require 'active_support/core_ext/string'
2
2
 
3
3
  module F1Results
4
4
  class Event
5
- attr_accessor :season, :country, :type, :name, :results
5
+ attr_accessor :year, :country, :type, :name, :results
6
6
 
7
- TYPES = {
7
+ TYPE_ALIASES = {
8
8
  p1: :practice1,
9
9
  p2: :practice2,
10
10
  p3: :practice3,
@@ -17,20 +17,17 @@ module F1Results
17
17
  args.each { |k,v| send("#{k}=", v) }
18
18
  end
19
19
 
20
- def country
21
- @country.titleize
20
+ def country_name
21
+ @country.to_s.titleize
22
22
  end
23
23
 
24
24
  def country_slug
25
- @country.parameterize
25
+ @country.to_s.parameterize
26
26
  end
27
27
 
28
28
  def type=(type)
29
- if type.to_s.length <= 2
30
- @type = TYPES[type]
31
- else
32
- @type = type
33
- end
29
+ type = type.to_s.downcase.gsub(' ', '').to_sym
30
+ @type = TYPE_ALIASES[type] || type
34
31
  end
35
32
 
36
33
  # Human readable type, e.g. "Practice 1", "Qualifying"
@@ -43,7 +40,7 @@ module F1Results
43
40
  end
44
41
 
45
42
  def practice?
46
- @type.to_s.gsub(/\d/, '') == 'practice'
43
+ /^practice(1|2|3)$/ =~ @type.to_s
47
44
  end
48
45
 
49
46
  def qualifying?
@@ -66,39 +63,14 @@ module F1Results
66
63
  @results.last.driver
67
64
  end
68
65
 
69
- def parse_results_table(table)
70
- @results = []
66
+ def fetch_results
67
+ agent = F1Results::Agent.new(self)
68
+ agent.fetch_results
69
+ end
71
70
 
72
- # Remove driver abbreviation from cell, shown only in race results
73
- table.xpath('//span[@class="tla"]').each(&:remove)
74
-
75
- # Turn HTML table into an array of arrays
76
- data = table.xpath('//tr').map do |row|
77
- row.xpath('./td').map do |cell|
78
- cell = cell.text.gsub(/[[:space:]]+/, ' ').strip
79
- cell.blank? ? nil : cell
80
- end
81
- end
82
-
83
- # Remove rows with empty position cells (Q1 107% Time), and table header if it's there
84
- data.reject! { |row| row[0].nil? || row[0] == 'P' }
85
-
86
- data.each_with_index do |row, i|
87
- klass = case
88
- when practice?
89
- PracticeResult
90
- when qualifying?
91
- QualifyingResult
92
- when race?
93
- RaceResult
94
- end
95
-
96
- result = klass.new(row)
97
- result.index = i
98
- @results << result
99
- end
100
-
101
- self
71
+ def fetch_results_with_url(url)
72
+ agent = F1Results::Agent.new(self)
73
+ agent.fetch_results_with_url(url)
102
74
  end
103
75
  end
104
76
  end
@@ -1,9 +1,21 @@
1
1
  module F1Results
2
2
  class Result
3
- attr_accessor :index, :position, :driver, :team, :laps
4
-
5
- def initialize(row = nil)
6
- build(row) unless row.nil?
3
+ attr_accessor :index, :position, :driver, :driver_number, :driver_country_abbr, :team, :time, :gap, :laps
4
+
5
+ alias :p= :position=
6
+ alias :pos= :position=
7
+ alias :name= :driver=
8
+ alias :no= :driver_number=
9
+ alias :country= :driver_country_abbr=
10
+ alias :best_time= :time=
11
+ alias :race_time= :time=
12
+ alias :fastest= :time=
13
+
14
+ def initialize(args = {})
15
+ args.each do |k, v|
16
+ # rescue here in case the results table has an obscure head cell like "Driver's Fastest Time"
17
+ send("#{k.to_s}=", v) rescue nil
18
+ end
7
19
  end
8
20
 
9
21
  def position=(n)
@@ -17,30 +29,23 @@ module F1Results
17
29
  end
18
30
  end
19
31
 
20
- private
32
+ def driver_number
33
+ @driver_number.to_i == 0 ? nil : @driver_number.to_i
34
+ end
21
35
 
22
- def build(row)
23
- self.position = row[0]
24
- @driver = row[1]
25
- row
26
- end
36
+ def laps
37
+ @laps.to_i < 1 ? nil : @laps.to_i
38
+ end
39
+
40
+ def gap
41
+ @gap.to_f == 0.0 ? nil : @gap.to_f
42
+ end
27
43
  end
28
44
 
29
45
  class PracticeResult < Result
30
- attr_accessor :time
31
-
32
46
  def to_a
33
- [position, driver, team, time, laps]
47
+ [position, driver_number, driver, team, time, gap, laps]
34
48
  end
35
-
36
- private
37
-
38
- def build(row)
39
- row = super
40
- @team = row[2]
41
- @time = row[3]
42
- @laps = row[4].to_i
43
- end
44
49
  end
45
50
 
46
51
  class QualifyingResult < Result
@@ -53,21 +58,12 @@ module F1Results
53
58
  def time
54
59
  q3 || q2 || q1
55
60
  end
56
-
57
- private
58
-
59
- def build(row)
60
- row = super
61
- @team = row[2]
62
- @q1 = row[3]
63
- @q2 = row[4]
64
- @q3 = row[5]
65
- @laps = row[6].to_i
66
- end
67
61
  end
68
62
 
69
63
  class RaceResult < Result
70
- attr_accessor :driver_country_abbr, :time, :retired, :points
64
+ attr_accessor :retired, :points
65
+
66
+ alias :points_awarded= :points=
71
67
 
72
68
  def to_a
73
69
  [position, driver, driver_country_abbr, team, time_or_retired, points]
@@ -85,14 +81,8 @@ module F1Results
85
81
  time || retired
86
82
  end
87
83
 
88
- private
89
-
90
- def build(row)
91
- row = super
92
- @driver_country_abbr = row[2]
93
- @team = row[3]
94
- self.time_or_retired = row[4]
95
- @points = row[5].to_i
96
- end
84
+ def points
85
+ @points.to_i
86
+ end
97
87
  end
98
88
  end
@@ -1,3 +1,3 @@
1
1
  module F1Results
2
- VERSION = '0.2-alpha.3'
2
+ VERSION = '0.6'
3
3
  end
data/lib/f1results.rb CHANGED
@@ -6,16 +6,22 @@ require 'f1results/result'
6
6
  module F1Results
7
7
  BASEURL = 'http://www.formula1.com'
8
8
 
9
- # Get results from formula1.com for a given season, country, and event type
9
+ # Get results from formula1.com for a given year, country, and event type
10
10
  # (race or qualifying)
11
11
  #
12
- # F1Results.get(2010, 'australia', :qualifying)
12
+ # F1Results.f1results(2010, 'australia', :qualifying)
13
13
  #
14
14
  # Returns an `F1Results::Event` object which has a method `results`, which
15
15
  # returns multiple objects of type `F1Results::Result`
16
16
 
17
- def self.get(year, country, type = :race)
18
- agent = F1Results::Agent.new
19
- agent.get_event(year, country, type)
17
+ def self.fetch(year, country, type = :race)
18
+ event = Event.new(year: year, country: country, type: type)
19
+ event.fetch_results
20
+ return event
21
+ end
22
+
23
+ def self.fetch_with_url(url)
24
+ agent = Agent.new
25
+ return agent.fetch_results_with_url(url)
20
26
  end
21
27
  end
data/test/agent_test.rb CHANGED
@@ -8,9 +8,9 @@ class AgentTest < MiniTest::Test
8
8
  end
9
9
 
10
10
  def test_get_event_2015_australia_race
11
- event = @agent.get_event(2015, 'Australia', :race)
12
- assert event.race?
13
- assert_equal 'Australia', event.country
11
+ event = F1Results::Event.new(year: 2015, country: 'Australia', type: :race)
12
+ @agent.event = event
13
+ @agent.fetch_results
14
14
  assert_equal '2015 FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX', event.name
15
15
  assert_equal 17, event.results.length
16
16
  assert_equal 'Lewis Hamilton', event.winner
@@ -18,9 +18,9 @@ class AgentTest < MiniTest::Test
18
18
  end
19
19
 
20
20
  def test_get_event_2015_australia_qualifying
21
- event = @agent.get_event(2015, 'Australia', :qualifying)
22
- assert event.qualifying?
23
- assert_equal 'Australia', event.country
21
+ event = F1Results::Event.new(year: 2015, country: 'Australia', type: :qualifying)
22
+ @agent.event = event
23
+ @agent.fetch_results
24
24
  assert_equal '2015 FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX', event.name
25
25
  assert_equal 20, event.results.length
26
26
  assert_equal 'Lewis Hamilton', event.winner
@@ -28,24 +28,47 @@ class AgentTest < MiniTest::Test
28
28
  end
29
29
 
30
30
  def test_get_event_2015_australia_practice1
31
- event = @agent.get_event(2015, 'Australia', :practice1)
32
- assert event.practice?
33
- assert_equal 'Australia', event.country
31
+ event = F1Results::Event.new(year: 2015, country: 'Australia', type: :practice1)
32
+ @agent.event = event
33
+ @agent.fetch_results
34
34
  assert_equal '2015 FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX', event.name
35
35
  assert_equal 16, event.results.length
36
36
  assert_equal 'Nico Rosberg', event.winner
37
37
  assert_equal 'Romain Grosjean', event.loser
38
38
  end
39
39
 
40
+ def test_get_event_2015_malaysia_practice2
41
+ event = F1Results::Event.new(year: 2015, country: 'Malaysia', type: :practice2)
42
+ @agent.event = event
43
+ @agent.fetch_results
44
+ assert_equal '2015 FORMULA 1 PETRONAS MALAYSIA GRAND PRIX', event.name
45
+ assert_equal 20, event.results.length
46
+ assert_equal 'Lewis Hamilton', event.winner
47
+ assert_equal 'Roberto Merhi', event.loser
48
+ end
49
+
50
+ def test_fetch_results_2015_hungary_race
51
+ event = @agent.fetch_results_with_url('http://www.formula1.com/content/fom-website/en/championship/results/2015-race-results/2015-Hungary-results/race.html')
52
+ assert_equal 'FORMULA 1 PIRELLI MAGYAR NAGYDÍJ 2015', event.name
53
+ assert_equal 'hungary', event.country
54
+ assert event.race?
55
+ assert_equal 20, event.results.length
56
+ assert_equal 'Sebastian Vettel', event.winner
57
+ assert_equal 'Nico Hulkenberg', event.loser
58
+ end
59
+
40
60
  def test_get_event_with_bad_year
41
- assert_raises RuntimeError, 'No results' do
42
- @agent.get_event(1900, 'Australia', :race)
61
+ assert_raises RuntimeError do
62
+ event = F1Results::Event.new(year: 1900, country: 'Australia', type: :race)
63
+ @agent.event = event
64
+ @agent.fetch_results
43
65
  end
44
66
  end
45
67
 
46
68
  def test_get_event_with_bad_grand_prix
47
- assert_raises RuntimeError, 'No results' do
48
- @agent.get_event(2015, 'New Zealand', :race)
69
+ assert_raises RuntimeError do
70
+ event = F1Results::Event.new(year: 2015, country: 'New Zealand', type: :race)
71
+ event.fetch_results
49
72
  end
50
73
  end
51
74
  end
data/test/event_test.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class EventTest < MiniTest::Test
4
+ include Fixtures
5
+
4
6
  def setup
5
7
  @event = F1Results::Event.new
6
- @event.results << F1Results::RaceResult.new([1, 'Mark Webber', 'AUS', 'Red Bull Racing-Renault', '1:25:11.288', 2])
7
- @event.results << F1Results::RaceResult.new([2, 'Fernando Alonso', 'ESP', 'Ferrari', '+3.0 secs', 1])
8
8
  end
9
9
 
10
10
  def test_type
@@ -12,16 +12,52 @@ class EventTest < MiniTest::Test
12
12
  assert_equal 'qualifying', @event.type_slug
13
13
  @event.type = :practice3
14
14
  assert_equal 'practice-3', @event.type_slug
15
+ @event.type = :p3
16
+ assert_equal :practice3, @event.type
17
+ end
18
+
19
+ def test_type_name
20
+ @event.type = :practice3
21
+ assert_equal 'Practice 3', @event.type_name
22
+ @event.type = :qualifying
23
+ assert_equal 'Qualifying', @event.type_name
24
+ @event.type = :race
25
+ assert_equal 'Race', @event.type_name
26
+ end
27
+
28
+ def test_type_setter_with_humanized_input
29
+ @event.type = 'Practice 3'
30
+ assert_equal :practice3, @event.type
31
+ @event.type = 'Qualifying'
32
+ assert_equal :qualifying, @event.type
33
+ @event.type = 'Race'
34
+ assert_equal :race, @event.type
35
+ end
36
+
37
+ def test_type_boolean_methods
38
+ @event.type = :race
39
+ assert @event.race?
40
+ @event.type = :qualifying
41
+ assert @event.qualifying?
42
+ @event.type = :practice1
43
+ assert @event.practice?
44
+ @event.type = :practice2
45
+ assert @event.practice?
46
+ @event.type = :practice3
47
+ assert @event.practice?
48
+ @event.type = :practice4
49
+ refute @event.practice?
15
50
  end
16
51
 
17
- def test_country
18
- @event.country = 'Australia'
19
- assert_equal 'Australia', @event.country
52
+ def test_country_name
20
53
  @event.country = 'great britain'
21
- assert_equal 'Great Britain', @event.country
54
+ assert_equal 'Great Britain', @event.country_name
22
55
  end
23
56
 
24
57
  def test_to_array
58
+ @event.results << F1Results::RaceResult.new(position: 1, driver: 'Mark Webber', driver_country_abbr: 'AUS', team: 'Red Bull Racing-Renault', time: '1:25:11.288', points: 2)
59
+ @event.results << F1Results::RaceResult.new(position: 2, driver: 'Fernando Alonso', driver_country_abbr: 'ESP', team: 'Ferrari', time: '+3.0 secs', points: 1)
60
+
25
61
  array = @event.to_a
26
62
  assert_equal 2, array.length
27
63
  assert_kind_of Array, array.first
data/test/result_test.rb CHANGED
@@ -30,7 +30,7 @@ class ResultTest < MiniTest::Test
30
30
  end
31
31
 
32
32
  def test_parse_practice
33
- result = F1Results::PracticeResult.new(['4', 'Carlos Sainz', 'Toro Rosso', '1:31.014', '32'])
33
+ result = F1Results::PracticeResult.new(position: '4', driver: 'Carlos Sainz', team: 'Toro Rosso', time: '1:31.014', laps: '32')
34
34
  assert_equal 4, result.position
35
35
  assert_equal 'Carlos Sainz', result.driver
36
36
  assert_equal 'Toro Rosso', result.team
@@ -39,7 +39,7 @@ class ResultTest < MiniTest::Test
39
39
  end
40
40
 
41
41
  def test_parse_qualifying
42
- result = F1Results::QualifyingResult.new(['2', 'Nico Rosberg', 'Mercedes', '1:28.906', '1:27.097', '1:26.921', '14'])
42
+ result = F1Results::QualifyingResult.new(position: '2', driver: 'Nico Rosberg', team: 'Mercedes', q1: '1:28.906', q2: '1:27.097', q3: '1:26.921', laps: '14')
43
43
  assert_equal 2, result.position
44
44
  assert_equal 'Nico Rosberg', result.driver
45
45
  assert_equal 'Mercedes', result.team
@@ -50,7 +50,7 @@ class ResultTest < MiniTest::Test
50
50
  end
51
51
 
52
52
  def test_parse_race
53
- result = F1Results::RaceResult.new(['3', 'Sebastian Vettel', 'GER', 'Ferrari', '+34.523s', '15'])
53
+ result = F1Results::RaceResult.new(position: '3', driver: 'Sebastian Vettel', driver_country_abbr: 'GER', team: 'Ferrari', time: '+34.523s', points: '15')
54
54
  assert_equal 3, result.position
55
55
  assert_equal 'Sebastian Vettel', result.driver
56
56
  assert_equal 'Ferrari', result.team
@@ -59,7 +59,7 @@ class ResultTest < MiniTest::Test
59
59
  end
60
60
 
61
61
  def test_parse_qualifying_with_blank_values
62
- result = F1Results::QualifyingResult.new(['16', 'Marcus Ericsson', 'Sauber', '1:31.376', nil, nil, 10])
62
+ result = F1Results::QualifyingResult.new(position: '16', driver: 'Marcus Ericsson', team: 'Sauber', q1: '1:31.376', q2: nil, q3: nil, laps: 10)
63
63
  assert_equal '1:31.376', result.q1
64
64
  assert_equal nil, result.q2
65
65
  assert_equal nil, result.q3
@@ -67,7 +67,13 @@ class ResultTest < MiniTest::Test
67
67
  end
68
68
 
69
69
  def test_race_to_a
70
- result = F1Results::RaceResult.new(['3', 'Sebastian Vettel', 'GER', 'Ferrari', '+34.523s', '15'])
70
+ result = F1Results::RaceResult.new(position: '3', driver: 'Sebastian Vettel', driver_country_abbr: 'GER', team: 'Ferrari', time: '+34.523s', points: '15')
71
71
  assert_equal [3, 'Sebastian Vettel', 'GER', 'Ferrari', '+34.523s', 15], result.to_a
72
72
  end
73
+
74
+ def test_unknown_key_doesnt_raise_error
75
+ assert_nothing_raised do
76
+ F1Results::Result.new(some_silly_column_name: 'value')
77
+ end
78
+ end
73
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: f1results
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.pre.alpha.3
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Jeacocke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-27 00:00:00.000000000 Z
11
+ date: 2016-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -128,12 +128,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ">"
131
+ - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 1.3.1
133
+ version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.4.6
136
+ rubygems_version: 2.4.5
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: F1 Results