Class: LocalSkiReport::Resort
- Inherits:
-
Object
- Object
- LocalSkiReport::Resort
- Defined in:
- lib/local_ski_report/resort.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#lifts ⇒ Object
Returns the value of attribute lifts.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
-
#reports ⇒ Object
Returns the value of attribute reports.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .clear ⇒ Object
- .create(html) ⇒ Object
- .find_by_location(location) ⇒ Object
- .sort_by_lifts_desc ⇒ Object
Instance Method Summary collapse
- #add_report(report) ⇒ Object
-
#initialize(name, url, location, lifts) ⇒ Resort
constructor
A new instance of Resort.
Constructor Details
#initialize(name, url, location, lifts) ⇒ Resort
Returns a new instance of Resort.
6 7 8 9 10 11 12 13 |
# File 'lib/local_ski_report/resort.rb', line 6 def initialize(name, url, location, lifts) @reports = [] @name = name @url = url @location = location @lifts = lifts @@all << self end |
Instance Attribute Details
#lifts ⇒ Object
Returns the value of attribute lifts.
2 3 4 |
# File 'lib/local_ski_report/resort.rb', line 2 def lifts @lifts end |
#location ⇒ Object
Returns the value of attribute location.
2 3 4 |
# File 'lib/local_ski_report/resort.rb', line 2 def location @location end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/local_ski_report/resort.rb', line 2 def name @name end |
#reports ⇒ Object
Returns the value of attribute reports.
2 3 4 |
# File 'lib/local_ski_report/resort.rb', line 2 def reports @reports end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/local_ski_report/resort.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
20 21 22 |
# File 'lib/local_ski_report/resort.rb', line 20 def self.all @@all end |
.clear ⇒ Object
24 25 26 |
# File 'lib/local_ski_report/resort.rb', line 24 def self.clear @@all.clear end |
.create(html) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/local_ski_report/resort.rb', line 28 def self.create(html) name = html.css('td div.name').text url = html.css('div.name a').first['href'] location = html.css('td div.rRegion').text lifts = html.css('td')[4].text.split("/").last self.new(name, url, location, lifts) end |
.find_by_location(location) ⇒ Object
36 37 38 |
# File 'lib/local_ski_report/resort.rb', line 36 def self.find_by_location(location) self.all.find_all { |resort| resort.location == location } end |
.sort_by_lifts_desc ⇒ Object
40 41 42 |
# File 'lib/local_ski_report/resort.rb', line 40 def self.sort_by_lifts_desc self.all.sort { |x, y| y.lifts.to_i <=> x.lifts.to_i } end |
Instance Method Details
#add_report(report) ⇒ Object
15 16 17 18 |
# File 'lib/local_ski_report/resort.rb', line 15 def add_report(report) report.resort = self self.reports << report end |