class SurfRockaway::Search
Public Class Methods
collect_data()
click to toggle source
# File lib/surf_data/search.rb, line 80 def self.collect_data # call #wave_options, @waves, #date_options, #time_options wave_options && @waves date_options time_options end
date_options()
click to toggle source
# File lib/surf_data/search.rb, line 52 def self.date_options # scrapes magicseaweed.com for dates @date = [] day_1 = @doc.search("tr.tbody-title").text.strip.split(" ").compact.first day_2 = @doc.search("tr.tbody-title").text.strip.split.slice(4..5).join(" ") day_3 = @doc.search("tr.tbody-title").text.strip.split.slice(6..7).join(" ") # returns data for each day && pushes data to instance variable @date @date << day_1 @date << day_2 @date << day_3 # calls @date @date end
search_by_size(selection)
click to toggle source
# File lib/surf_data/search.rb, line 91 def self.search_by_size(selection) # calls #collect_data collect_data # create array to store day, time, and wave size as nested hash wave_sizes = [ { :day => "#{@date[0]}", :time => "#{@time[0]}", :size => "#{@size[0]}" }, { :day => "#{@date[0]}", :time => "#{@time[1]}", :size => "#{@size[1]}" }, { :day => "#{@date[0]}", :time => "#{@time[2]}", :size => "#{@size[2]}" }, { :day => "#{@date[0]}", :time => "#{@time[3]}", :size => "#{@size[3]}" }, { :day => "#{@date[0]}", :time => "#{@time[4]}", :size => "#{@size[4]}" }, { :day => "#{@date[1]}", :time => "#{@time[0]}", :size => "#{@size[5]}" }, { :day => "#{@date[1]}", :time => "#{@time[1]}", :size => "#{@size[6]}" }, { :day => "#{@date[1]}", :time => "#{@time[2]}", :size => "#{@size[7]}" }, { :day => "#{@date[1]}", :time => "#{@time[3]}", :size => "#{@size[8]}" }, { :day => "#{@date[1]}", :time => "#{@time[4]}", :size => "#{@size[9]}" }, { :day => "#{@date[2]}", :time => "#{@time[0]}", :size => "#{@size[10]}" }, { :day => "#{@date[2]}", :time => "#{@time[1]}", :size => "#{@size[11]}" }, { :day => "#{@date[2]}", :time => "#{@time[2]}", :size => "#{@size[12]}" }, { :day => "#{@date[2]}", :time => "#{@time[3]}", :size => "#{@size[13]}" }, { :day => "#{@date[2]}", :time => "#{@time[4]}", :size => "#{@size[14]}" }, ] # selection argument captured on ./cli.rb # selection compared to key :size by iterating over array #wave_sizes wave_sizes.select {|i| i[:size] == selection} end
time_options()
click to toggle source
# File lib/surf_data/search.rb, line 71 def self.time_options # scrapes magicseaweed.com for times && returns @times variable @time = @doc.search("td.nopadding-left").text.strip.split[2..6] @time end
wave_options()
click to toggle source
# File lib/surf_data/search.rb, line 36 def self.wave_options # scrapes magicseaweed.com for wave size each day day_1 = @doc.search("td.background-info").text.strip.split[2..6] day_2 = @doc.search("td.background-info").text.strip.split[10..14] day_3 = @doc.search("td.background-info").text.strip.split[18..22] # combines days into a variable called "waves" # returns "waves" as an array with only unique values @size = day_1 + day_2 + day_3 @size.uniq end