class PontDelPetroli::Meteo::Parser

Constants

CSS_ROWS_SELECTOR
DATA_URL
EMPTY_CHAR

Public Instance Methods

run() click to toggle source
# File lib/meteo/parser.rb, line 11
def run
  rows = Nokogiri::HTML(open(DATA_URL)).css CSS_ROWS_SELECTOR
  
  rows.drop(1).map do |row|
    extract_data_from row
  end.compact
end

Private Instance Methods

extract_data_from(row) click to toggle source
# File lib/meteo/parser.rb, line 21
def extract_data_from row
  return if is_empty? row

  timestamp      = Time.parse row.css('td:nth-child(1)').text
  temperature    = row.css('td:nth-child(2)').text
  rain           = row.css('td:nth-child(4)').text
  wind_speed     = row.css('td:nth-child(5)').text
  wind_direction = row.css('td:nth-child(6)').text

  Data.new timestamp, temperature, rain, wind_speed, wind_direction
end
is_empty?(row) click to toggle source
# File lib/meteo/parser.rb, line 33
def is_empty? row
  row.css('td:nth-child(2)').text == EMPTY_CHAR
end