Class: LocalSkiReport::Resort

Inherits:
Object
  • Object
show all
Defined in:
lib/local_ski_report/resort.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#liftsObject

Returns the value of attribute lifts.



2
3
4
# File 'lib/local_ski_report/resort.rb', line 2

def lifts
  @lifts
end

#locationObject

Returns the value of attribute location.



2
3
4
# File 'lib/local_ski_report/resort.rb', line 2

def location
  @location
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/local_ski_report/resort.rb', line 2

def name
  @name
end

#reportsObject

Returns the value of attribute reports.



2
3
4
# File 'lib/local_ski_report/resort.rb', line 2

def reports
  @reports
end

#urlObject

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

.allObject



20
21
22
# File 'lib/local_ski_report/resort.rb', line 20

def self.all
    @@all
end

.clearObject



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_descObject



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