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



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



20
21
22
# File 'lib/rock_n_roll/race.rb', line 20

def self.all
  @@all
end

.new_from_list(race) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/rock_n_roll/race.rb', line 12

def self.new_from_list(race)
  url = race.css("h5 a").attribute("href").text
  if !url.end_with?("/")
    url += "/"
  end
  self.new(race.css("h5 a").text, url)
end

.retrieve(input) ⇒ Object



24
25
26
# File 'lib/rock_n_roll/race.rb', line 24

def self.retrieve(input)
  self.all[input.to_i - 1]
end

Instance Method Details

#race_siteObject



28
29
30
# File 'lib/rock_n_roll/race.rb', line 28

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