provincias 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 ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in provincias.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Javier Toledo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Provincias
2
+
3
+ Stop storing spanish provinces in a static table in your database. Use this gem with its class Provincia and reclaim a few bytes of your storage quota.
4
+
5
+ ## Thanks
6
+
7
+ Province names and codes were gently stolen from 'provincias_espana_rails' gem, a database-based solution for the same problem: https://github.com/diacode/provincias_espana_rails
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'provincias'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install provincias
22
+
23
+ ## Usage
24
+
25
+ Install the gem as described before and use Province class to find and show province names.
26
+
27
+ You may want to include the Provincias module in your classes to access the Provicia class directly. In other case it will be namespaced under Provincias::Provincia.
28
+
29
+ The interface is simmilar to ActiveRecord's and provides provinces numeric codes you can use to search or easily link provinces to your classes.
30
+
31
+ Provincia.find(id) => "Some Province Name"
32
+ Provincia.find_by_name('Madrid') => Provincia(:id => 35, :name => 'Palmas, Las')
33
+ Provincia.find_by_name('wombat') => nil
34
+ Provincia.all => [...] # An array of Provincia instances
35
+ Provincia.all_for_select => [...] # An array in form [name, id] to use in select helpers in Rails
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Provincias
2
+ VERSION = "0.0.1"
3
+ end
data/lib/provincias.rb ADDED
@@ -0,0 +1,91 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "provincias/version"
3
+
4
+ module Provincias
5
+ class Provincia
6
+
7
+ attr_reader :id, :name
8
+
9
+ def initialize(hash)
10
+ @id = hash[:id]
11
+ @name = hash[:name]
12
+ end
13
+
14
+ def self.find(id)
15
+ @@provincias.each do |p|
16
+ return Provincia.new(p) if id == p[:id]
17
+ end
18
+ nil
19
+ end
20
+
21
+ def self.find_by_name(name)
22
+ @@provincias.each do |p|
23
+ return Provincia.new(p) if name == p[:name]
24
+ end
25
+ nil
26
+ end
27
+
28
+ def self.all
29
+ @@provincias.map { |p| Provincia.new(p) }
30
+ end
31
+
32
+ def self.all_for_select
33
+ @@provincias.map { |p| [p[:name], p[:id]] }
34
+ end
35
+
36
+ private
37
+ @@provincias = [
38
+ {:id => 1, :name => 'Álava'},
39
+ {:id => 2, :name => 'Albacete'},
40
+ {:id => 3, :name => 'Alicante'},
41
+ {:id => 4, :name => 'Almería'},
42
+ {:id => 5, :name => 'Avila'},
43
+ {:id => 6, :name => 'Badajoz'},
44
+ {:id => 7, :name => 'Illes Baleares'},
45
+ {:id => 8, :name => 'Barcelona'},
46
+ {:id => 9, :name => 'Burgos'},
47
+ {:id => 10, :name => 'Cáceres'},
48
+ {:id => 11, :name => 'Cádiz'},
49
+ {:id => 12, :name => 'Cástellón'},
50
+ {:id => 13, :name => 'Ciudad Real'},
51
+ {:id => 14, :name => 'Córdoba'},
52
+ {:id => 15, :name => 'Coruña, A'},
53
+ {:id => 16, :name => 'Cuenca'},
54
+ {:id => 17, :name => 'Girona'},
55
+ {:id => 18, :name => 'Granada'},
56
+ {:id => 19, :name => 'Guadalajara'},
57
+ {:id => 20, :name => 'Guipuzcoa'},
58
+ {:id => 21, :name => 'Huelva'},
59
+ {:id => 22, :name => 'Huesca'},
60
+ {:id => 23, :name => 'Jaén'},
61
+ {:id => 24, :name => 'León'},
62
+ {:id => 25, :name => 'Lleida'},
63
+ {:id => 26, :name => 'Rioja, La'},
64
+ {:id => 27, :name => 'Lugo'},
65
+ {:id => 28, :name => 'Madrid'},
66
+ {:id => 29, :name => 'Málaga'},
67
+ {:id => 30, :name => 'Murcia'},
68
+ {:id => 31, :name => 'Navarra'},
69
+ {:id => 32, :name => 'Ourense'},
70
+ {:id => 33, :name => 'Asturias'},
71
+ {:id => 34, :name => 'Palencia'},
72
+ {:id => 35, :name => 'Palmas, Las'},
73
+ {:id => 36, :name => 'Pontevedra'},
74
+ {:id => 37, :name => 'Salamanca'},
75
+ {:id => 38, :name => 'Santa Cruz de Tenerife'},
76
+ {:id => 39, :name => 'Cantabria'},
77
+ {:id => 40, :name => 'Segovia'},
78
+ {:id => 41, :name => 'Sevilla'},
79
+ {:id => 42, :name => 'Soria'},
80
+ {:id => 43, :name => 'Tarragona'},
81
+ {:id => 44, :name => 'Teruel'},
82
+ {:id => 45, :name => 'Toledo'},
83
+ {:id => 46, :name => 'Valencia'},
84
+ {:id => 47, :name => 'Valladolid'},
85
+ {:id => 48, :name => 'Vizcaya'},
86
+ {:id => 49, :name => 'Zamora'},
87
+ {:id => 50, :name => 'Zaragoza'},
88
+ {:id => 51, :name => 'Ceuta'},
89
+ {:id => 52, :name => 'Melilla'}]
90
+ end
91
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/provincias/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Javier Toledo"]
6
+ gem.email = ["javier@theagilemonkeys.com"]
7
+ gem.description = %q{Provides a Provincia class to search for spanish province names with numeric ids to link to your application data.}
8
+ gem.summary = %q{Stop storing spanish provinces in a static table in your database. Use this gem with its class Provincia, reclaim a few bytes of your storage quota and sanitize your DB structure from unuseful static data.}
9
+ gem.homepage = "https://github.com/agilemonkeys/provincias"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "provincias"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Provincias::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: provincias
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Javier Toledo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-19 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Provides a Provincia class to search for spanish province names with
15
+ numeric ids to link to your application data.
16
+ email:
17
+ - javier@theagilemonkeys.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - lib/provincias.rb
28
+ - lib/provincias/version.rb
29
+ - provincias.gemspec
30
+ homepage: https://github.com/agilemonkeys/provincias
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.24
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Stop storing spanish provinces in a static table in your database. Use this
54
+ gem with its class Provincia, reclaim a few bytes of your storage quota and sanitize
55
+ your DB structure from unuseful static data.
56
+ test_files: []
57
+ has_rdoc: