mityc-geoportal 0.0.7 → 0.0.8

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/README.md CHANGED
@@ -22,4 +22,27 @@ provinces.each { |province|
22
22
  cities = province.cities
23
23
  }
24
24
 
25
- ```
25
+ ```
26
+
27
+ # License
28
+
29
+ Copyright (c) 2012 Vicente Reig Rincón de Arellano
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ "Software"), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
45
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
46
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
47
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
48
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -8,7 +8,7 @@ end
8
8
 
9
9
  require "happymapper"
10
10
  require "httparty"
11
-
11
+ require "mityc-geoportal/ext/array"
12
12
  require "mityc-geoportal/version"
13
13
  require "mityc-geoportal/fuel"
14
14
  require "mityc-geoportal/city"
@@ -0,0 +1,18 @@
1
+ class Array
2
+ def by_attribute(attr_name)
3
+ group_by_attribute(attr_name)
4
+ groups_by_attribute.each { |attr_value, items| yield attr_value, items }
5
+ end
6
+
7
+ protected
8
+ def group_by_attribute(attr_name)
9
+ self.groups_by_attribute = {}
10
+ self.each { |item|
11
+ attr_value = item.send(attr_name.to_sym)
12
+ self.groups_by_attribute[attr_value] ||= []
13
+ self.groups_by_attribute[attr_value] << item
14
+ }
15
+ end
16
+
17
+ attr_accessor :groups_by_attribute
18
+ end
@@ -5,13 +5,19 @@ class Mityc::Geoportal::Fuel
5
5
 
6
6
  tag "tipocombustible"
7
7
 
8
- element :id, Integer, tag: "id"
8
+ element :id, Integer, tag: "id"
9
9
  element :name, String, tag: "nombre"
10
10
 
11
- # TODO: Properly implement an Identiy Map
12
11
  def measures
13
12
  @measures ||= Mityc::Geoportal::Measure.by_fuel(self.id)
14
13
  end
14
+
15
+ def measures_by(field_name)
16
+ self.measures.by_attribute(field_name) { |field_value, measure_group|
17
+ yield field_value, measure_group
18
+ }
19
+ end
20
+
15
21
  class << self
16
22
  def all
17
23
  @fuels ||= self.parse(fuels_xml)
@@ -66,6 +66,7 @@ class Mityc::Geoportal::Measure
66
66
  self.fuel_id = fuel_id
67
67
  @measures ||= self.parse(measures_html)
68
68
  end
69
+
69
70
  protected
70
71
  def measures_html
71
72
  response_body = self.get('/searchTotal.do', query: query_params).body
@@ -1,5 +1,5 @@
1
1
  module Mityc
2
2
  module Geoportal
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mityc-geoportal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-24 00:00:00.000000000 Z
12
+ date: 2012-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: unhappymapper
16
- requirement: &70333197906160 !ruby/object:Gem::Requirement
16
+ requirement: &70100011381900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70333197906160
24
+ version_requirements: *70100011381900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &70333197905700 !ruby/object:Gem::Requirement
27
+ requirement: &70100011381460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70333197905700
35
+ version_requirements: *70100011381460
36
36
  description: Simple wrapper to the fuel prices published by the Spanish Government
37
37
  through http://geoportal.mityc.es/
38
38
  email:
@@ -49,6 +49,7 @@ files:
49
49
  - Rakefile
50
50
  - lib/mityc-geoportal.rb
51
51
  - lib/mityc-geoportal/city.rb
52
+ - lib/mityc-geoportal/ext/array.rb
52
53
  - lib/mityc-geoportal/fuel.rb
53
54
  - lib/mityc-geoportal/measure.rb
54
55
  - lib/mityc-geoportal/province.rb