class PontDelPetroli::Swell::Parser

Constants

CSS_ROWS_SELECTOR
DATA_URL
EMPTY_CHAR

Public Instance Methods

run() click to toggle source
# File lib/swell/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/swell/parser.rb, line 21
def extract_data_from row
  return if is_empty? row

  timestamp = Time.parse row.css('td:nth-child(1)').text
  height    = row.css('td:nth-child(4)').text
  direction = row.css('td:nth-child(5)').text
  period    = row.css('td:nth-child(6)').text

  Data.new timestamp, height, direction, period
end
is_empty?(row) click to toggle source
# File lib/swell/parser.rb, line 32
def is_empty? row
  row.css('td:nth-child(4)').text == EMPTY_CHAR
end