Class: RockNRoll::Race

Inherits:
Object
  • Object
show all
Defined in:
lib/rock_n_roll/race.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dateObject

Returns the value of attribute date.



2
3
4
# File 'lib/rock_n_roll/race.rb', line 2

def date
  @date
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/rock_n_roll/race.rb', line 2

def description
  @description
end

#distancesObject

Returns the value of attribute distances.



2
3
4
# File 'lib/rock_n_roll/race.rb', line 2

def distances
  @distances
end

#hashtagObject

Returns the value of attribute hashtag.



2
3
4
# File 'lib/rock_n_roll/race.rb', line 2

def hashtag
  @hashtag
end

#locationObject

Returns the value of attribute location.



2
3
4
# File 'lib/rock_n_roll/race.rb', line 2

def location
  @location
end

#urlObject

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

.allObject



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_siteObject



34
35
36
# File 'lib/rock_n_roll/race.rb', line 34

def race_site
  @race_site ||= Nokogiri::HTML(open(self.url))
end