class SurfRockaway::SurfReport
Attributes
date[RW]
location[RW]
primary_swell[RW]
temp[RW]
time[RW]
wave_size[RW]
weather[RW]
wind[RW]
Public Class Methods
current()
click to toggle source
# File lib/surf_data/surf_report.rb, line 6 def self.current # Scrape magicseaweed.com and return current conditions for rockaway puts "### Pulling current report ... this may take up to 10 seconds ###" puts "" self.scrape_data end
multi_day()
click to toggle source
# File lib/surf_data/surf_report.rb, line 30 def self.multi_day # Scrape 3-day forecast puts "### Pulling current report ... this may take up to 15 seconds ###" puts "" self.scrape_data_multi end
scrape_data()
click to toggle source
# File lib/surf_data/surf_report.rb, line 17 def self.scrape_data # creates empty array to store data conditions = [] # pushes new instances of data from magicseaweed.com to conditions array conditions << self.scrape_magicseaweed conditions end
scrape_data_multi()
click to toggle source
# File lib/surf_data/surf_report.rb, line 41 def self.scrape_data_multi multi_day = [] # pushes new instances of data for 3-day forcast to multi_day array multi_day << self.scrape_magicseaweed_3day # returns the array multi_day end
scrape_magicseaweed()
click to toggle source
# File lib/surf_data/surf_report.rb, line 55 def self.scrape_magicseaweed # scrape current surf report current_report = self.new location_raw = @doc.search("div.forecast-sub-title-fluid").text.strip.split current_report.location = location_raw.first(5).join(" ") current_report.wave_size = @doc.xpath("//ul[@class='rating rating-large clearfix']/li").text.strip current_report.wind = @doc.xpath("//p[@class='h5 nomargin-top']").text.strip p_swell = @doc.search("div.list-group-content").text.strip.split current_report.primary_swell = p_swell.first(3).join(" ") current_report.weather = @doc.xpath("//p[@class='nomargin-bottom']/i").text.strip # CLI OUTPUT puts "================================" puts "#{current_report.location}" puts "================================" puts "" puts " Wave Size: // #{current_report.wave_size} //".blue puts " Wind: // #{current_report.wind} // ".blue puts " Primary_swell: // #{current_report.primary_swell} //".blue puts " Weather: // #{current_report.weather} //".blue puts "" puts "" puts "######################################" end
scrape_magicseaweed_3day()
click to toggle source
# File lib/surf_data/surf_report.rb, line 83 def self.scrape_magicseaweed_3day # collect Day 1 day_1 = self.new day_1.date = @doc.search("tr.tbody-title").text.strip.split(" ").compact.first day_1.time = @doc.search("td.nopadding-left").text.strip.split[2..6] day_1.wave_size = @doc.search("td.background-info").text.strip.split[2..6] day_1.primary_swell = @doc.search("h4.font-sans-serif").text.strip.split[4..13] day_1.temp = @doc.search("h5.heavy").text.strip.split("f")[2..6] day_1 # collect Day 2 day_2 = self.new day_2.date = @doc.search("tr.tbody-title").text.strip.split.slice(4..5).join(" ") day_2.time = @doc.search("td.nopadding-left").text.strip.split[2..6] day_2.wave_size = @doc.search("td.background-info").text.strip.split[10..14] day_2.primary_swell = @doc.search("h4.font-sans-serif").text.strip.split[20..29] day_2.temp = @doc.search("h5.heavy").text.strip.split("f")[10..14] day_2 # collect Day 3 day_3 = self.new day_3.date = @doc.search("tr.tbody-title").text.strip.split.slice(6..7).join(" ") day_3.time = @doc.search("td.nopadding-left").text.strip.split[2..6] day_3.wave_size = @doc.search("td.background-info").text.strip.split[18..22] day_3.primary_swell = @doc.search("h4.font-sans-serif").text.strip.split[36..45] day_3.temp = @doc.search("h5.heavy").text.strip.split("f")[18..22] day_3 # CLI DISPLAY FOR 3 DAY FORECAST # day 1 puts "" puts "===========================" puts "#{day_1.date}" puts "===========================" table = TTY::Table.new ['', 'wave_size', 'primary_swell', 'temp'], [ ["#{day_1.time[0]}", "#{day_1.wave_size[0]}", "#{day_1.primary_swell[0]}", "#{day_1.temp[0]}"], ["#{day_1.time[1]}", "#{day_1.wave_size[1]}", "#{day_1.primary_swell[2]}", "#{day_1.temp[1]}"], ["#{day_1.time[2]}", "#{day_1.wave_size[2]}", "#{day_1.primary_swell[4]}", "#{day_1.temp[2]}"], ["#{day_1.time[3]}", "#{day_1.wave_size[3]}", "#{day_1.primary_swell[6]}", "#{day_1.temp[3]}"], ["#{day_1.time[4]}", "#{day_1.wave_size[4]}", "#{day_1.primary_swell[8]}", "#{day_1.temp[4]}"] ] puts table.render(:ascii).green # day 2 puts "" puts "===========================" puts "#{day_2.date}" puts "===========================" table = TTY::Table.new ['', 'wave_size', 'primary_swell', 'temp'], [ ["#{day_2.time[0]}", "#{day_2.wave_size[0]}", "#{day_2.primary_swell[0]}", "#{day_2.temp[0]}"], ["#{day_2.time[1]}", "#{day_2.wave_size[1]}", "#{day_2.primary_swell[2]}", "#{day_2.temp[1]}"], ["#{day_2.time[2]}", "#{day_2.wave_size[2]}", "#{day_2.primary_swell[4]}", "#{day_2.temp[2]}"], ["#{day_2.time[3]}", "#{day_2.wave_size[3]}", "#{day_2.primary_swell[6]}", "#{day_2.temp[3]}"], ["#{day_2.time[4]}", "#{day_2.wave_size[4]}", "#{day_2.primary_swell[8]}", "#{day_2.temp[4]}"] ] puts table.render(:ascii).green # day 3 puts "" puts "===========================" puts "#{day_3.date}" puts "===========================" table = TTY::Table.new ['', 'wave_size', 'primary_swell', 'temp'], [ ["#{day_3.time[0]}", "#{day_3.wave_size[0]}", "#{day_3.primary_swell[0]}", "#{day_3.temp[0]}"], ["#{day_3.time[1]}", "#{day_3.wave_size[1]}", "#{day_3.primary_swell[2]}", "#{day_3.temp[1]}"], ["#{day_3.time[2]}", "#{day_3.wave_size[2]}", "#{day_3.primary_swell[4]}", "#{day_3.temp[2]}"], ["#{day_3.time[3]}", "#{day_3.wave_size[3]}", "#{day_3.primary_swell[6]}", "#{day_3.temp[3]}"], ["#{day_3.time[4]}", "#{day_3.wave_size[4]}", "#{day_3.primary_swell[8]}", "#{day_3.temp[4]}"] ] puts table.render(:ascii).green puts "" puts "" puts "######################################" end