anp_prices 1.0 → 1.01

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0
1
+ 1.01
data/anp_prices.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.authors = ["Rogério Zambon"]
4
- s.date = "2013-01-10"
4
+ s.date = "2013-01-12"
5
5
  s.description = "Get fuel prices of the ANP - Agência Nacional do Petróleo, Gás Natural e Biocombustíveis"
6
6
  s.email = "rogeriozambon@gmail.com"
7
7
  s.add_dependency "rest-client", ">= 1.6.7"
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
  s.required_rubygems_version = Gem::Requirement.new(">= 1.8.23")
20
20
  s.summary = s.description
21
- s.version = "1.0"
21
+ s.version = "1.01"
22
22
  end
data/lib/anp_prices.rb CHANGED
@@ -7,7 +7,7 @@ class ANP
7
7
  def initialize(city = nil, fuel = nil)
8
8
  raise ArgumentError if city.nil? or fuel.nil?
9
9
 
10
- @city = city
10
+ @city = find_code_of(city)
11
11
  @fuel = fuel
12
12
  end
13
13
 
@@ -50,6 +50,22 @@ class ANP
50
50
  Nokogiri::HTML(req.body).xpath "//div[@class='multi_box3']/table[@class='table_padrao scrollable_table']"
51
51
  end
52
52
 
53
+ def request_city(name)
54
+ req = RestClient.post "http://www.anp.gov.br/preco/prc/Resumo_Ultimas_Coletas_Index.asp", :txtMunicipio => name
55
+
56
+ Nokogiri::HTML(req.body).xpath "//div[@id='divMunicipios']/select[@name='selMunicipio']/option"
57
+ end
58
+
59
+ def find_code_of(name)
60
+ request_city(name).each do |node|
61
+ node.each_with_index do |code, index|
62
+ next if index == 0
63
+
64
+ return code[1]
65
+ end
66
+ end
67
+ end
68
+
53
69
  def push_values_with(lines)
54
70
  entry = []
55
71
  entries = []
@@ -5,12 +5,26 @@ describe ANP do
5
5
  expect { anp = ANP.new }.to raise_error(ArgumentError)
6
6
  end
7
7
 
8
+ context "Find city code" do
9
+ before do
10
+ fixture = File.open("spec/fixture/city_sao_paulo.html").read
11
+ parser = Nokogiri::HTML(fixture).xpath "//div[@id='divMunicipios']/select[@name='selMunicipio']/option"
12
+
13
+ @anp = ANP.new "Sao Paulo", :gasolina
14
+ @anp.stub(:request_city).and_return(parser)
15
+ end
16
+
17
+ it "check city code" do
18
+ @anp.city.should == "9668*SAO@PAULO"
19
+ end
20
+ end
21
+
8
22
  context "Informations" do
9
23
  before do
10
24
  fixture = File.open("spec/fixture/anp_sao_paulo.html").read
11
25
  parser = Nokogiri::HTML(fixture).xpath("//div[@class='multi_box3']/table[@class='table_padrao scrollable_table']")
12
26
 
13
- @anp = ANP.new "9668*SAO@PAULO", :gasolina
27
+ @anp = ANP.new "Sao Paulo", :gasolina
14
28
  @anp.stub(:request_page).and_return(parser)
15
29
  end
16
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anp_prices
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.01'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
12
+ date: 2013-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client