Class: LocalSkiReport::Report
- Inherits:
-
Object
- Object
- LocalSkiReport::Report
- Defined in:
- lib/local_ski_report/report.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#date ⇒ Object
Returns the value of attribute date.
-
#elevation ⇒ Object
Returns the value of attribute elevation.
-
#lifts_open ⇒ Object
Returns the value of attribute lifts_open.
-
#new_snow ⇒ Object
Returns the value of attribute new_snow.
-
#resort ⇒ Object
Returns the value of attribute resort.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tickets ⇒ Object
Returns the value of attribute tickets.
-
#trails ⇒ Object
Returns the value of attribute trails.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .clear ⇒ Object
- .create(html) ⇒ Object
- .get_lift_status(html) ⇒ Object
- .get_status(state) ⇒ Object
Instance Method Summary collapse
- #get_ticket_prices(row) ⇒ Object
- #get_xt_report_info(html) ⇒ Object
-
#initialize(date, url, status, new_snow, base, lifts_open) ⇒ Report
constructor
A new instance of Report.
- #report ⇒ Object
- #xt_report ⇒ Object
Constructor Details
#initialize(date, url, status, new_snow, base, lifts_open) ⇒ Report
Returns a new instance of Report.
6 7 8 9 10 11 12 13 14 |
# File 'lib/local_ski_report/report.rb', line 6 def initialize(date, url, status, new_snow, base, lifts_open) @date = date @url = url @status = status @new_snow = new_snow @base = base @lifts_open = lifts_open @@all << self end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
2 3 4 |
# File 'lib/local_ski_report/report.rb', line 2 def base @base end |
#date ⇒ Object
Returns the value of attribute date.
2 3 4 |
# File 'lib/local_ski_report/report.rb', line 2 def date @date end |
#elevation ⇒ Object
Returns the value of attribute elevation.
2 3 4 |
# File 'lib/local_ski_report/report.rb', line 2 def elevation @elevation end |
#lifts_open ⇒ Object
Returns the value of attribute lifts_open.
2 3 4 |
# File 'lib/local_ski_report/report.rb', line 2 def lifts_open @lifts_open end |
#new_snow ⇒ Object
Returns the value of attribute new_snow.
2 3 4 |
# File 'lib/local_ski_report/report.rb', line 2 def new_snow @new_snow end |
#resort ⇒ Object
Returns the value of attribute resort.
2 3 4 |
# File 'lib/local_ski_report/report.rb', line 2 def resort @resort end |
#status ⇒ Object
Returns the value of attribute status.
2 3 4 |
# File 'lib/local_ski_report/report.rb', line 2 def status @status end |
#tickets ⇒ Object
Returns the value of attribute tickets.
2 3 4 |
# File 'lib/local_ski_report/report.rb', line 2 def tickets @tickets end |
#trails ⇒ Object
Returns the value of attribute trails.
2 3 4 |
# File 'lib/local_ski_report/report.rb', line 2 def trails @trails end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/local_ski_report/report.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
16 17 18 |
# File 'lib/local_ski_report/report.rb', line 16 def self.all @@all end |
.clear ⇒ Object
20 21 22 |
# File 'lib/local_ski_report/report.rb', line 20 def self.clear @@all.clear end |
.create(html) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/local_ski_report/report.rb', line 24 def self.create(html) date = html.css('div.lUpdate').text url = html.css('td')[3].css('a').first['href'] status = self.get_status(html.css('td')[1].css('div').first['class'].split(" ").pop) if html.css('td')[2].css('b')[0] new_snow = html.css('td')[2].css('b')[0].text else new_snow = 'N/A' end base = html.css('td')[3].css('b')[0].text lifts_open = self.get_lift_status(html) self.new(date, url, status, new_snow, base, lifts_open) end |
.get_lift_status(html) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/local_ski_report/report.rb', line 38 def self.get_lift_status(html) if html.css('td')[4].text.split("/").first == "" 0 else html.css('td')[4].text.split("/").first end end |
.get_status(state) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/local_ski_report/report.rb', line 46 def self.get_status(state) case state when "stateD1" "Open" when "stateD2" "Closed" else "Weekends Only" end end |
Instance Method Details
#get_ticket_prices(row) ⇒ Object
57 58 59 60 |
# File 'lib/local_ski_report/report.rb', line 57 def get_ticket_prices(row) arr = row.css('td').text.gsub("US","").split [arr[1], arr[3]] end |
#get_xt_report_info(html) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/local_ski_report/report.rb', line 68 def get_xt_report_info(html) table = html.css('table') rows = table.css('tr') @elevation = rows[1].css('td').text.split(" - ") @trails = rows[2].css('td').text.gsub("|","").split @tickets = get_ticket_prices(rows[4]) end |
#report ⇒ Object
62 63 64 65 66 |
# File 'lib/local_ski_report/report.rb', line 62 def report rows = [] rows << [self.resort.name, {:value => self.date, :alignment => :center}, self.status, {:value => self.new_snow, :alignment => :center},{:value => self.base, :alignment => :center}, {:value => "#{self.lifts_open}/#{resort.lifts}", :alignment => :right}] Terminal::Table.new :title => "Ski Report", :headings => ['Resort Name', 'Updated On', 'Status', 'New Snow', 'Base Depth', 'Lifts Open'], :rows => rows end |
#xt_report ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/local_ski_report/report.rb', line 76 def xt_report rows = [] rows << ['ELEVATION', "Base:", "#{elevation[0]}", "Summit:", "#{elevation[1]}"] rows << ["TRAILS", "Beginner: #{trails[0]}", "Intermediate: #{trails[1]}", "Advanced: #{trails[2]}", "Expert: #{trails[3]}"] rows << ["TICKET PRICES", "Starting at:", "#{tickets[0]}", {:value => "to", :alignment => :center}, "#{tickets[1]}"] table = Terminal::Table.new :title => "#{self.resort.name} Full Report", :rows => rows table.style = {:all_separators => true} table end |