ine-places 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ codigo provincia,codigo autonomia,nombre,slug,lon,lat
2
+ 2,8,Albacete,albacete,-1.8585424,38.994349
3
+ 3,10,Alicante/Alacant,alicante,-0.4906855,38.3459963
4
+ 4,1,Almería,almeria,-2.4637136,36.834047
5
+ 1,16,Araba/Álava,alava,-2.6983868,42.9099989
6
+ 33,3,Asturias,asturias,-5.8593267,43.3613953
7
+ 5,7,Ávila,avila,-4.6812086,40.656685
8
+ 6,11,Badajoz,badajoz,-6.9706535,38.8794495
9
+ 7,4,"Balears, Illes",baleares,2.8577105,39.5341789
10
+ 8,9,Barcelona,barcelona,2.0832941,41.297445
11
+ 48,16,Bizkaia,bizkaia,-2.6983868,43.2204286
12
+ 9,7,Burgos,burgos,-3.696906,42.3439925
13
+ 10,11,Cáceres,caceres,-6.3724247,39.4752765
14
+ 11,1,Cádiz,cadiz,-6.2885962,36.5270612
15
+ 39,6,Cantabria,cantabria,-3.9878427,43.1828396
16
+ 12,10,Castellón/Castelló,castellon,-0.0513246,39.9863563
17
+ 51,18,Ceuta,ceuta,-5.3213455,35.8893874
18
+ 13,8,Ciudad Real,ciudad-real,-3.927377799999999,38.9848295
19
+ 14,1,Córdoba,cordoba,-4.7793835,37.8881751
20
+ 15,12,"Coruña, A",coruna-a,-8.4115401,43.3623436
21
+ 16,8,Cuenca,cuenca,-2.1374162,40.0703925
22
+ 20,16,Gipuzkoa,gipuzkoa,-2.2236667,43.0756299
23
+ 17,9,Girona,girona,2.8214264,41.9794005
24
+ 18,1,Granada,granada,-3.5985571,37.1773363
25
+ 19,8,Guadalajara,guadalajara,-3.16017,40.632489
26
+ 21,1,Huelva,huelva,-6.9447224,37.261421
27
+ 22,2,Huesca,huesca,-0.4078058,42.131845
28
+ 23,1,Jaén,jaen,-3.784905699999999,37.7795941
29
+ 24,7,León,leon,-5.5670959,42.5987263
30
+ 27,12,Lugo,lugo,-7.5567582,43.0097384
31
+ 25,9,Lleida,lleida,0.6200146,41.6175899
32
+ 28,13,Madrid,madrid,-3.7037902,40.4167754
33
+ 29,1,Málaga,malaga,-4.4212655,36.721261
34
+ 52,19,Melilla,melilla,-2.9380973,35.2922775
35
+ 30,14,Murcia,murcia,-1.1306544,37.9922399
36
+ 31,15,Navarra,navarra,-1.6760691,42.6953909
37
+ 32,12,Ourense,ourense,-7.863880999999998,42.33578929999999
38
+ 34,7,Palencia,palencia,-4.5288016,42.0096857
39
+ 35,5,"Palmas, Las",las-palmas,-15.4362574,28.1235459
40
+ 36,12,Pontevedra,pontevedra,-8.6446202,42.4298846
41
+ 26,17,"Rioja, La",la-rioja,-2.4631181,36.9450225
42
+ 37,7,Salamanca,salamanca,-5.663539699999999,40.9701039
43
+ 38,5,Santa Cruz de Tenerife,tenerife,-16.2518467,28.4636296
44
+ 40,7,Segovia,segovia,-4.108806899999999,40.9429032
45
+ 41,1,Sevilla,sevilla,-5.89305,37.4201674
46
+ 42,7,Soria,soria,-2.4790306,41.7665972
47
+ 43,9,Tarragona,tarragona,1.2444909,41.1188827
48
+ 44,2,Teruel,teruel,-1.1064345,40.3456879
49
+ 45,8,Toledo,toledo,-4.027323099999999,39.8628316
50
+ 46,10,Valencia/València,valencia,-0.3762881,39.4699075
51
+ 47,7,Valladolid,valladolid,-4.724532099999999,41.652251
52
+ 49,7,Zamora,zamora,-5.7467879,41.5034712
53
+ 50,2,Zaragoza,zaragoza,-0.8890853,41.6488226
@@ -0,0 +1,24 @@
1
+ class INE::Places::Place < OpenStruct
2
+ include INE::Places::CSVRecord
3
+
4
+ def self.find_all_by_province_id(province_id)
5
+ return [] if province_id.blank?
6
+
7
+ collection_klass.records.select{ |place| place.province_id == province_id }
8
+ end
9
+
10
+ private
11
+
12
+ def self.collection_klass
13
+ INE::Places::PlacesCollection
14
+ end
15
+
16
+ def self.filter(records, name)
17
+ return [] if name.blank?
18
+ parameterized_name = name.parameterize
19
+
20
+ records.select{|p| p.slug.include?(parameterized_name) }.
21
+ reject{|p| ['ceuta','melilla'].include?(p.slug) }.
22
+ sort_by{|p| p.province.slug }
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require "ine/places/version"
2
+ require "csv"
3
+ require "ostruct"
4
+ require "active_support/all"
5
+
6
+ module INE
7
+ module Places
8
+ ROOT = File.expand_path('../', __FILE__)
9
+
10
+ def self.preload
11
+ AutonomousRegionsCollection.records
12
+ ProvincesCollection.records
13
+ PlacesCollection.records
14
+
15
+ nil
16
+ end
17
+ end
18
+ end
19
+
20
+ require "ine/places/csv_record"
21
+ require "ine/places/autonomous_region"
22
+ require "ine/places/autonomous_regions_collection"
23
+ require "ine/places/province"
24
+ require "ine/places/provinces_collection"
25
+ require "ine/places/place"
26
+ require "ine/places/places_collection"
@@ -0,0 +1,20 @@
1
+ class INE::Places::PlacesCollection
2
+ include Singleton
3
+
4
+ def self.records
5
+ @records ||= CSV.read("#{INE::Places::ROOT}/data/places.csv", headers: true).map do |raw_data|
6
+ build_from_raw_data(raw_data)
7
+ end.sort_by(&:slug)
8
+ end
9
+
10
+ def self.build_from_raw_data(raw_data)
11
+ INE::Places::Place.new({
12
+ id: raw_data[0], name: raw_data[2],
13
+ slug: raw_data[3], province_id: raw_data[1],
14
+ lon: raw_data[6], lat: raw_data[7],
15
+ province: INE::Places::Province.find(raw_data[1])
16
+ })
17
+ end
18
+ private_class_method :build_from_raw_data
19
+
20
+ end
@@ -0,0 +1,28 @@
1
+ class INE::Places::Province < OpenStruct
2
+ include INE::Places::CSVRecord
3
+
4
+ def self.find_all_by_autonomous_region_id(autonomous_region_id)
5
+ return [] if autonomous_region_id.blank?
6
+
7
+ collection_klass.records.select{ |province| province.autonomous_region_id == autonomous_region_id }
8
+ end
9
+
10
+ def places
11
+ INE::Places::Place.find_all_by_province_id(self.id)
12
+ end
13
+
14
+ private
15
+
16
+ def self.collection_klass
17
+ INE::Places::ProvincesCollection
18
+ end
19
+
20
+ def self.filter(records, name)
21
+ return [] if name.blank?
22
+ parameterized_name = name.parameterize
23
+
24
+ records.select{|p| p.slug.include?(parameterized_name) }.
25
+ reject{|p| ['ceuta','melilla'].include?(p.slug) }.
26
+ sort_by{|p| p.autonomous_region.slug }
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ class INE::Places::ProvincesCollection
2
+ include Singleton
3
+
4
+ def self.records
5
+ @records ||= CSV.read("#{INE::Places::ROOT}/data/provinces.csv", headers: true).map do |raw_data|
6
+ build_from_raw_data(raw_data)
7
+ end.sort_by(&:slug)
8
+ end
9
+
10
+ def self.build_from_raw_data(raw_data)
11
+ INE::Places::Province.new({
12
+ id: raw_data[0], name: raw_data[2],
13
+ slug: raw_data[3], autonomous_region_id: raw_data[1],
14
+ lon: raw_data[4], lat: raw_data[5],
15
+ autonomous_region: INE::Places::AutonomousRegion.find(raw_data[1])
16
+ })
17
+ end
18
+ private_class_method :build_from_raw_data
19
+
20
+ end
@@ -0,0 +1,5 @@
1
+ module INE
2
+ module Places
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ine-places
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fernando Blat
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Work with Spanish regions using INE codes and data
70
+ email:
71
+ - ferblape@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - ine-places.gemspec
85
+ - lib/ine/places/autonomous_region.rb
86
+ - lib/ine/places/autonomous_regions_collection.rb
87
+ - lib/ine/places/csv_record.rb
88
+ - lib/ine/places/data/autonomous_regions.csv
89
+ - lib/ine/places/data/places.csv
90
+ - lib/ine/places/data/provinces.csv
91
+ - lib/ine/places/place.rb
92
+ - lib/ine/places/places.rb
93
+ - lib/ine/places/places_collection.rb
94
+ - lib/ine/places/province.rb
95
+ - lib/ine/places/provinces_collection.rb
96
+ - lib/ine/places/version.rb
97
+ homepage: https://github.com/PopulateTools/ine-places
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ allowed_push_host: https://rubygems.org
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.5.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: An easy way to work with Spanish regions in Ruby
122
+ test_files: []
123
+ has_rdoc: