Class: RockNRoll::Race
- Inherits:
-
Object
- Object
- RockNRoll::Race
- Defined in:
- lib/rock_n_roll/race.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#description ⇒ Object
Returns the value of attribute description.
-
#distances ⇒ Object
Returns the value of attribute distances.
-
#hashtag ⇒ Object
Returns the value of attribute hashtag.
-
#location ⇒ Object
Returns the value of attribute location.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(location = nil, url = nil) ⇒ Race
constructor
A new instance of Race.
- #race_site ⇒ Object
Constructor Details
#initialize(location = nil, url = nil) ⇒ Race
Returns a new instance of Race.
6 7 8 9 10 |
# File 'lib/rock_n_roll/race.rb', line 6 def initialize(location = nil, url = nil) @location = location @url = url @@all << self end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
2 3 4 |
# File 'lib/rock_n_roll/race.rb', line 2 def date @date end |
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/rock_n_roll/race.rb', line 2 def description @description end |
#distances ⇒ Object
Returns the value of attribute distances.
2 3 4 |
# File 'lib/rock_n_roll/race.rb', line 2 def distances @distances end |
#hashtag ⇒ Object
Returns the value of attribute hashtag.
2 3 4 |
# File 'lib/rock_n_roll/race.rb', line 2 def hashtag @hashtag end |
#location ⇒ Object
Returns the value of attribute location.
2 3 4 |
# File 'lib/rock_n_roll/race.rb', line 2 def location @location end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/rock_n_roll/race.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
26 27 28 |
# File 'lib/rock_n_roll/race.rb', line 26 def self.all @@all end |
.new_from_list(race) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rock_n_roll/race.rb', line 12 def self.new_from_list(race) location = race.css("h3 a").text if location == "" location = "TBD" end url = "https://www.runrocknroll.com" + race.css("h3 a").attribute("href").text if !url.end_with?("/") url += "/" elsif url == "" url = "TBD" end self.new(location, url) end |
.retrieve(input) ⇒ Object
30 31 32 |
# File 'lib/rock_n_roll/race.rb', line 30 def self.retrieve(input) self.all[input.to_i - 1] end |
Instance Method Details
#race_site ⇒ Object
34 35 36 |
# File 'lib/rock_n_roll/race.rb', line 34 def race_site @race_site ||= Nokogiri::HTML(open(self.url)) end |