Class: ANP

Inherits:
Object
  • Object
show all
Defined in:
lib/anp_prices.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(city = nil, fuel = nil) ⇒ ANP

Returns a new instance of ANP.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
# File 'lib/anp_prices.rb', line 7

def initialize(city = nil, fuel = nil)
  raise ArgumentError if city.nil? or fuel.nil?

  RestClient.proxy = ENV["http_proxy"]

  @city = find_code_of(city)
  @fuel = fuel
end

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city.



5
6
7
# File 'lib/anp_prices.rb', line 5

def city
  @city
end

#fuelObject (readonly)

Returns the value of attribute fuel.



5
6
7
# File 'lib/anp_prices.rb', line 5

def fuel
  @fuel
end

Instance Method Details

#pricesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/anp_prices.rb', line 16

def prices
  lines = []

  request_page.each do |node|
    node.inner_html.each_line.with_index do |line, index|
      next if index < 34

      line.encode! "ISO-8859-1", "UTF-8", :invalid => :replace, :replace => "?"
      line.gsub! /<(.*?)>/, ""

      lines << line.strip
    end
  end

  push_values_with lines
end