-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d7f593d
Showing
8 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in provincias.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2012 Javier Toledo | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Provincias | ||
|
||
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. | ||
|
||
## Thanks | ||
|
||
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 | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
gem 'provincias' | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install provincias | ||
|
||
## Usage | ||
|
||
Install the gem as described before and use Province class to find and show province names. | ||
|
||
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. | ||
|
||
The interface is simmilar to ActiveRecord's and provides provinces numeric codes you can use to search or easily link provinces to your classes. | ||
|
||
Provincia.find(id) => "Some Province Name" | ||
Provincia.find_by_name('Madrid') => Provincia(:id => 35, :name => 'Palmas, Las') | ||
Provincia.find_by_name('wombat') => nil | ||
Provincia.all => [...] # An array of Provincia instances | ||
Provincia.all_for_select => [...] # An array in form [name, id] to use in select helpers in Rails | ||
|
||
## Contributing | ||
|
||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Added some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# -*- encoding: utf-8 -*- | ||
require "provincias/version" | ||
|
||
module Provincias | ||
class Provincia | ||
|
||
attr_reader :id, :name | ||
|
||
def initialize(hash) | ||
@id = hash[:id] | ||
@name = hash[:name] | ||
end | ||
|
||
def self.find(id) | ||
@@provincias.each do |p| | ||
return Provincia.new(p) if id == p[:id] | ||
end | ||
nil | ||
end | ||
|
||
def self.find_by_name(name) | ||
@@provincias.each do |p| | ||
return Provincia.new(p) if name == p[:name] | ||
end | ||
nil | ||
end | ||
|
||
def self.all | ||
@@provincias.map { |p| Provincia.new(p) } | ||
end | ||
|
||
def self.all_for_select | ||
@@provincias.map { |p| [p[:name], p[:id]] } | ||
end | ||
|
||
private | ||
@@provincias = [ | ||
{:id => 1, :name => 'Álava'}, | ||
{:id => 2, :name => 'Albacete'}, | ||
{:id => 3, :name => 'Alicante'}, | ||
{:id => 4, :name => 'Almería'}, | ||
{:id => 5, :name => 'Avila'}, | ||
{:id => 6, :name => 'Badajoz'}, | ||
{:id => 7, :name => 'Illes Baleares'}, | ||
{:id => 8, :name => 'Barcelona'}, | ||
{:id => 9, :name => 'Burgos'}, | ||
{:id => 10, :name => 'Cáceres'}, | ||
{:id => 11, :name => 'Cádiz'}, | ||
{:id => 12, :name => 'Cástellón'}, | ||
{:id => 13, :name => 'Ciudad Real'}, | ||
{:id => 14, :name => 'Córdoba'}, | ||
{:id => 15, :name => 'Coruña, A'}, | ||
{:id => 16, :name => 'Cuenca'}, | ||
{:id => 17, :name => 'Girona'}, | ||
{:id => 18, :name => 'Granada'}, | ||
{:id => 19, :name => 'Guadalajara'}, | ||
{:id => 20, :name => 'Guipuzcoa'}, | ||
{:id => 21, :name => 'Huelva'}, | ||
{:id => 22, :name => 'Huesca'}, | ||
{:id => 23, :name => 'Jaén'}, | ||
{:id => 24, :name => 'León'}, | ||
{:id => 25, :name => 'Lleida'}, | ||
{:id => 26, :name => 'Rioja, La'}, | ||
{:id => 27, :name => 'Lugo'}, | ||
{:id => 28, :name => 'Madrid'}, | ||
{:id => 29, :name => 'Málaga'}, | ||
{:id => 30, :name => 'Murcia'}, | ||
{:id => 31, :name => 'Navarra'}, | ||
{:id => 32, :name => 'Ourense'}, | ||
{:id => 33, :name => 'Asturias'}, | ||
{:id => 34, :name => 'Palencia'}, | ||
{:id => 35, :name => 'Palmas, Las'}, | ||
{:id => 36, :name => 'Pontevedra'}, | ||
{:id => 37, :name => 'Salamanca'}, | ||
{:id => 38, :name => 'Santa Cruz de Tenerife'}, | ||
{:id => 39, :name => 'Cantabria'}, | ||
{:id => 40, :name => 'Segovia'}, | ||
{:id => 41, :name => 'Sevilla'}, | ||
{:id => 42, :name => 'Soria'}, | ||
{:id => 43, :name => 'Tarragona'}, | ||
{:id => 44, :name => 'Teruel'}, | ||
{:id => 45, :name => 'Toledo'}, | ||
{:id => 46, :name => 'Valencia'}, | ||
{:id => 47, :name => 'Valladolid'}, | ||
{:id => 48, :name => 'Vizcaya'}, | ||
{:id => 49, :name => 'Zamora'}, | ||
{:id => 50, :name => 'Zaragoza'}, | ||
{:id => 51, :name => 'Ceuta'}, | ||
{:id => 52, :name => 'Melilla'}] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Provincias | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- encoding: utf-8 -*- | ||
require File.expand_path('../lib/provincias/version', __FILE__) | ||
|
||
Gem::Specification.new do |gem| | ||
gem.authors = ["Javier Toledo"] | ||
gem.email = ["[email protected]"] | ||
gem.description = %q{Provides a Provincia class to search for and use spanish province in your apps.} | ||
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.} | ||
gem.homepage = "https://github.com/agilemonkeys/provincias" | ||
|
||
gem.files = `git ls-files`.split($\) | ||
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } | ||
gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) | ||
gem.name = "provincias" | ||
gem.require_paths = ["lib"] | ||
gem.version = Provincias::VERSION | ||
end |