Class: Kit::Member
- Inherits:
-
Object
- Object
- Kit::Member
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/kit/member.rb
Overview
An individual USA Cycling member
Instance Attribute Summary collapse
-
#races ⇒ Object
readonly
Returns the value of attribute races.
Class Method Summary collapse
-
.from_table(table) ⇒ Kit::Member
Given an HTML table of races, return a
Memberwith that collection of races.
Instance Method Summary collapse
-
#initialize(races = []) ⇒ Member
constructor
A new instance of Member.
-
#limited_to(years) ⇒ Kit::Member
Returns a
Memberwith a collection of races limited to the given list of years.
Constructor Details
#initialize(races = []) ⇒ Member
Returns a new instance of Member.
54 55 56 |
# File 'lib/kit/member.rb', line 54 def initialize(races = []) @races = races end |
Instance Attribute Details
#races ⇒ Object (readonly)
Returns the value of attribute races.
38 39 40 |
# File 'lib/kit/member.rb', line 38 def races @races end |
Class Method Details
.from_table(table) ⇒ Kit::Member
Given an HTML table of races, return a Member with that collection of races
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kit/member.rb', line 13 def self.from_table(table) date_parser = DateParser.new maybe_content = -> (element) { element.nil? ? nil : element.content } races = table.map do |race_row, result_row| [ result_row.css('td')[2].content, [ race_row.css('a').first.content, maybe_content.call(race_row.css('[title=age]').first) ].compact.join(' '), result_row.css('td')[0].content, date_parser.parse(race_row), result_row.css('td').last.content ] end.map do |args| Kit::Race.new(*args) end new(races) end |
Instance Method Details
#limited_to(years) ⇒ Kit::Member
Returns a Member with a collection of races limited to the given list of years.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/kit/member.rb', line 63 def limited_to(years) selected_races = years.reduce([]) do |races, year| lower = Date.strptime("#{year}-01-01") upper = Date.strptime("#{Integer(year) + 1}-01-01") races | @races.select do |race| race.date >= lower && race.date < upper end end self.class.new(selected_races) end |