class NaturalGasParser

Public Class Methods

new(options = {}) click to toggle source
# File lib/earth/residence/residence_fuel_price/data_miner.rb, line 74
def initialize(options = {})
  # nothing
end

Public Instance Methods

apply(row) click to toggle source
# File lib/earth/residence/residence_fuel_price/data_miner.rb, line 77
def apply(row)
  virtual_rows = []
  row.keys.grep(/\A(.*) Natural Gas/) do |location_column_name|
    match_1 = $1
    next if (price = row[location_column_name]).blank? or (date = row['Date']).blank?
    if match_1 == 'U.S.'
      locatable_id = 'US'
      locatable_type = 'Country'
    else
      locatable_id = match_1 # name
      locatable_type = 'State'
    end
    date = Time.parse(date)
    new_row = ActiveSupport::OrderedHash.new
    new_row['locatable_id'] = locatable_id
    new_row['locatable_type'] = locatable_type
    new_row['price'] = price
    new_row['year'] = date.year
    new_row['month'] = date.month
    row_hash = RemoteTable::Transform.row_hash new_row
    new_row['row_hash'] = row_hash
    virtual_rows << new_row
  end
  virtual_rows
end