Module: Gassy

Defined in:
lib/gassy.rb,
lib/gassy/version.rb,
lib/gassy/gassy_utils.rb,
lib/gassy/gassy_constants.rb

Overview

Utility classes used by GassyUtils

Defined Under Namespace

Modules: GassyConstants, GassyUtils

Constant Summary collapse

VERSION =
"1.0.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.fileObject (readonly)

Returns the value of attribute file.



17
18
19
# File 'lib/gassy.rb', line 17

def file
  @file
end

Class Method Details

.extract_one_price(entity) ⇒ Object

Get one Price for an entity and return it as a Float. Return nil if the entity is not found

Example:

>> boston_price = gassy.extract_one_price("Boston")
  • entity - An entity to look up a price for. Can be a city, state, or region.



45
46
47
48
49
50
51
# File 'lib/gassy.rb', line 45

def extract_one_price(entity)
  init_file
  condensed = GassyUtils.condense_xml(@file)
  remove_diesel = condensed.match(/.*On-Highway/).to_s
  listing = remove_diesel.match(/\d*.\d*\D*#{entity.gsub(/\s+/, "")}(<)/).to_s
  price = listing.match(/\d*.\d*/).to_s.to_f  
end

.get_all_price_dataObject

Get all Price Data and return it as a nested hash

Example:

>> price_hash = gassy.get_all_price_data


26
27
28
29
30
31
32
33
34
# File 'lib/gassy.rb', line 26

def get_all_price_data
  @data = {:cities => {}, :states => {}, :regions => {}}
  @data.each_key do |key|
    GassyUtils.send("#{key}").each do |entity|
      @data[key][entity] = extract_one_price(entity)
    end
  end
  @data
end

.load_datafile(file_path) ⇒ Object

This will force the cached datafile to be refreshed with a locally provided file.

Example:

>> Gassy.load_datafile
  • file_path - The path to the file to process



73
74
75
# File 'lib/gassy.rb', line 73

def load_datafile(file_path)
    init_file(true, file_path)
end

.refresh_datafileObject

This will force the cached datafile to be refreshed with new data from the website.

Example:

>> Gassy.refresh_datafile


60
61
62
# File 'lib/gassy.rb', line 60

def refresh_datafile
  init_file(true)
end