mityc-geoportal 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.rvmrc +39 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/mityc-geoportal.rb +16 -0
- data/lib/mityc-geoportal/city.rb +27 -0
- data/lib/mityc-geoportal/fuel.rb +29 -0
- data/lib/mityc-geoportal/measure.rb +79 -0
- data/lib/mityc-geoportal/province.rb +24 -0
- data/lib/mityc-geoportal/version.rb +5 -0
- data/mityc-geoportal.gemspec +25 -0
- metadata +79 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.3-p125@mityc-geoportal"
|
8
|
+
|
9
|
+
# First we attempt to load the desired environment directly from the environment
|
10
|
+
# file. This is very fast and efficient compared to running through the entire
|
11
|
+
# CLI and selector. If you want feedback on which environment was used then
|
12
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
13
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
14
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
15
|
+
then
|
16
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
17
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
18
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
19
|
+
else
|
20
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
21
|
+
rvm --create "$environment_id" || {
|
22
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
23
|
+
return 1
|
24
|
+
}
|
25
|
+
fi
|
26
|
+
|
27
|
+
# If you use bundler, this might be useful to you:
|
28
|
+
# if [[ -s Gemfile ]] && {
|
29
|
+
# ! builtin command -v bundle >/dev/null ||
|
30
|
+
# builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
|
31
|
+
# }
|
32
|
+
# then
|
33
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
34
|
+
# gem install bundler
|
35
|
+
# fi
|
36
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
37
|
+
# then
|
38
|
+
# bundle install | grep -vE '^Using|Your bundle is complete'
|
39
|
+
# fi
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Mityc
|
2
|
+
module Geoportal
|
3
|
+
def self.base_uri
|
4
|
+
'http://geoportal.mityc.es/hidrocarburos/eess'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require "happymapper"
|
10
|
+
require "httparty"
|
11
|
+
|
12
|
+
require "mityc-geoportal/version"
|
13
|
+
require "mityc-geoportal/fuel"
|
14
|
+
require "mityc-geoportal/city"
|
15
|
+
require "mityc-geoportal/province"
|
16
|
+
require "mityc-geoportal/measure"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Mityc::Geoportal::City
|
2
|
+
include HappyMapper, HTTParty
|
3
|
+
|
4
|
+
base_uri Mityc::Geoportal::base_uri
|
5
|
+
|
6
|
+
tag 'm'
|
7
|
+
|
8
|
+
content :name, String
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :province_id
|
12
|
+
|
13
|
+
def by_province(province_id)
|
14
|
+
self.province_id = province_id
|
15
|
+
@cities ||= self.parse(cities_xml)
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def cities_xml
|
20
|
+
self.get('/municipios.do', query: query_params).body
|
21
|
+
end
|
22
|
+
|
23
|
+
def query_params
|
24
|
+
{ tipoBusqueda: 0, idProvincia: self.province_id }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Mityc::Geoportal::Fuel
|
2
|
+
include HappyMapper, HTTParty
|
3
|
+
|
4
|
+
base_uri Mityc::Geoportal::base_uri
|
5
|
+
|
6
|
+
tag "tipocombustible"
|
7
|
+
|
8
|
+
element :id, Integer, tag: "id"
|
9
|
+
element :name, String, tag: "nombre"
|
10
|
+
|
11
|
+
# TODO: Properly implement an Identiy Map
|
12
|
+
def measures
|
13
|
+
@measures ||= Mityc::Geoportal::Measure.by_fuel(self.id)
|
14
|
+
end
|
15
|
+
class << self
|
16
|
+
def all
|
17
|
+
@fuels ||= self.parse(fuels_xml)
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
def fuels_xml
|
22
|
+
self.get('/combustibles.do', query: query_params).body
|
23
|
+
end
|
24
|
+
|
25
|
+
def query_params
|
26
|
+
{ tipoBusqueda: 0 }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class Mityc::Geoportal::Measure
|
2
|
+
include HappyMapper, HTTParty
|
3
|
+
|
4
|
+
base_uri Mityc::Geoportal::base_uri
|
5
|
+
|
6
|
+
tag 'tr[position()>4]'
|
7
|
+
|
8
|
+
element :province_name, String, xpath: 'td[1]'
|
9
|
+
element :city_name, String, xpath: 'td[2]'
|
10
|
+
element :address, String, xpath: 'td[3]'
|
11
|
+
element :margin, String, xpath: 'td[4]'
|
12
|
+
element :label, String, xpath: 'td[7]'
|
13
|
+
element :public_sale, String, xpath: 'td[8]'
|
14
|
+
element :data_source, String, xpath: 'td[9]'
|
15
|
+
element :schedule, String, xpath: 'td[10]'
|
16
|
+
element :measured_at, String, xpath: 'td[5]'
|
17
|
+
element :amount, String, xpath: 'td[6]'
|
18
|
+
|
19
|
+
def amount
|
20
|
+
@amount.gsub(/,/, ".").to_f
|
21
|
+
end
|
22
|
+
|
23
|
+
def measured_at
|
24
|
+
@measured_at = @measured_at.split(/\//).map(&:to_i).reverse
|
25
|
+
@measured_at = Date.new(*@measured_at)
|
26
|
+
end
|
27
|
+
|
28
|
+
def public_sale
|
29
|
+
(@public_sale =~/^p$/i)? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
def data_source
|
33
|
+
@data_source.strip
|
34
|
+
end
|
35
|
+
|
36
|
+
def schedule
|
37
|
+
@schedule.strip
|
38
|
+
end
|
39
|
+
|
40
|
+
def province_name
|
41
|
+
@province_name.strip
|
42
|
+
end
|
43
|
+
|
44
|
+
def city_name
|
45
|
+
@city_name.strip
|
46
|
+
end
|
47
|
+
|
48
|
+
def address
|
49
|
+
@address.strip
|
50
|
+
end
|
51
|
+
|
52
|
+
def margin
|
53
|
+
@margin = @margin.strip
|
54
|
+
if @margin =~ /^$i/i
|
55
|
+
"left"
|
56
|
+
elsif @margin =~/^d$/i
|
57
|
+
"right"
|
58
|
+
else
|
59
|
+
"none"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class << self
|
64
|
+
attr_accessor :fuel_id
|
65
|
+
|
66
|
+
def by_fuel(fuel_id)
|
67
|
+
self.fuel_id = fuel_id
|
68
|
+
@measures ||= self.parse(measures_html)
|
69
|
+
end
|
70
|
+
protected
|
71
|
+
def measures_html
|
72
|
+
self.get('/searchTotal.do', query: query_params).body
|
73
|
+
end
|
74
|
+
|
75
|
+
def query_params
|
76
|
+
{ tipoCons: 1, tipoBusqueda: 0, tipoCarburante: self.fuel_id }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Mityc::Geoportal::Province
|
2
|
+
include HappyMapper, HTTParty
|
3
|
+
|
4
|
+
base_uri Mityc::Geoportal::base_uri
|
5
|
+
|
6
|
+
tag 'provincia'
|
7
|
+
element :id, String, tag: 'id_provincia'
|
8
|
+
element :name, String, tag: 'nombre_provincia'
|
9
|
+
|
10
|
+
def cities
|
11
|
+
@cities ||= Mityc::Geoportal::City.by_province(self.id)
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def all
|
16
|
+
@provinces ||= self.parse(provinces_xml)
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
def provinces_xml
|
21
|
+
self.get('/provincias.do').body
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mityc-geoportal/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "mityc-geoportal"
|
7
|
+
s.version = Mityc::Geoportal::VERSION
|
8
|
+
s.authors = ["Vicente Reig Rincón de Arellano"]
|
9
|
+
s.email = ["vicente.reig@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/vicentereig/mityc-geoportal"
|
11
|
+
s.summary = %q{Provides access to the fuel prices published by the Spanish Government.}
|
12
|
+
s.description = %q{Simple wrapper to the fuel prices published by the Spanish Government through http://geoportal.mityc.es/}
|
13
|
+
|
14
|
+
s.rubyforge_project = "mityc-geoportal"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "unhappymapper"
|
24
|
+
s.add_runtime_dependency "httparty"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mityc-geoportal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vicente Reig Rincón de Arellano
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: unhappymapper
|
16
|
+
requirement: &70141077812400 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70141077812400
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
requirement: &70141077811940 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70141077811940
|
36
|
+
description: Simple wrapper to the fuel prices published by the Spanish Government
|
37
|
+
through http://geoportal.mityc.es/
|
38
|
+
email:
|
39
|
+
- vicente.reig@gmail.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- .rvmrc
|
46
|
+
- Gemfile
|
47
|
+
- Rakefile
|
48
|
+
- lib/mityc-geoportal.rb
|
49
|
+
- lib/mityc-geoportal/city.rb
|
50
|
+
- lib/mityc-geoportal/fuel.rb
|
51
|
+
- lib/mityc-geoportal/measure.rb
|
52
|
+
- lib/mityc-geoportal/province.rb
|
53
|
+
- lib/mityc-geoportal/version.rb
|
54
|
+
- mityc-geoportal.gemspec
|
55
|
+
homepage: http://github.com/vicentereig/mityc-geoportal
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project: mityc-geoportal
|
75
|
+
rubygems_version: 1.8.17
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Provides access to the fuel prices published by the Spanish Government.
|
79
|
+
test_files: []
|