class Puertos::RowParser
The Parser
is responsible of fetching the data from Puertos
del Estado and return it as ruby objects
Attributes
row[R]
Public Class Methods
new(row)
click to toggle source
# File lib/row_parser.rb, line 10 def initialize row @row = row end
Public Instance Methods
run()
click to toggle source
parses each input line and returns a ForecastData
object
@return [ForecastData] with all the relevant information
# File lib/row_parser.rb, line 17 def run timestamp = create_timestamp wind = create_wind_data total_swell = create_total_swell_data wind_swell = create_wind_swell_data ground_swell_1 = create_ground_swell_data_1 ground_swell_2 = create_ground_swell_data_2 ForecastData.new timestamp, wind, total_swell, wind_swell, ground_swell_1, ground_swell_2 end
Private Instance Methods
create_ground_swell_data_1()
click to toggle source
# File lib/row_parser.rb, line 46 def create_ground_swell_data_1 Puertos::SwellData.new height: read_column(12), direction: read_column(13), avg_period: read_column(14) end
create_ground_swell_data_2()
click to toggle source
# File lib/row_parser.rb, line 50 def create_ground_swell_data_2 Puertos::SwellData.new height: read_column(15), direction: read_column(16), avg_period: read_column(17) end
create_timestamp()
click to toggle source
# File lib/row_parser.rb, line 30 def create_timestamp Time.parse read_column(1) end
create_total_swell_data()
click to toggle source
# File lib/row_parser.rb, line 38 def create_total_swell_data Puertos::SwellData.new height: read_column(6), direction: read_column(7), avg_period: read_column(9), peak_period: read_column(8) end
create_wind_data()
click to toggle source
# File lib/row_parser.rb, line 34 def create_wind_data Puertos::WindData.new speed: read_column(4), direction: read_column(5) end
create_wind_swell_data()
click to toggle source
# File lib/row_parser.rb, line 42 def create_wind_swell_data Puertos::SwellData.new height: read_column(10), direction: read_column(11) end
read_column(number)
click to toggle source
# File lib/row_parser.rb, line 54 def read_column number row.css("td:nth-child(#{number})").text.strip end