Class: SkiReport::Report
- Inherits:
-
Object
- Object
- SkiReport::Report
- Defined in:
- lib/ski_report/report.rb
Class Method Summary collapse
Class Method Details
.print_report(state) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ski_report/report.rb', line 20 def self.print_report(state) report_data = scrape_ots(state.gsub(/\s/, '-').downcase) #takes state and formats it for scraping longest_resort = report_data.max_by {|report| report[:name].length}[:name].length puts "\nSnow Report's for #{state}:" printf("%-#{longest_resort + 1}s|%10s|%10s|%10s\n", "Resort", "24Hr Total", "72Hr Total", "Base Depth") puts "-------------------------------------------------------------------" report_data.each do |resort| printf("%-#{longest_resort + 1}s| %-6s| %-6s|%10s\n", resort[:name], resort[:twofour] + '"', resort[:seventwo] + '"', resort[:base]) end end |
.scrape_ots(state_url) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ski_report/report.rb', line 3 def self.scrape_ots(state_url) resorts = [] doc = Nokogiri::HTML(open("http://www.onthesnow.com/" + state_url + "/skireport.html?&ud=1&o=resort")) doc.css(".resScrollCol8 table tr").each do |resort| if resort.css('.name').text != "" new_resort = { :name => resort.css('.name').text, :twofour => resort.css('.rLeft b').first.text.slice(/\d+/), :seventwo => resort.css('.rLeft b').last.text.slice(/\d+/), :base => resort.css('.rMid b').text } resorts << new_resort end end resorts end |