provincias 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Provincias
2
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.
3
+ Stop storing spanish provinces in a static table in your database. Use this gem and reclaim a few bytes of your storage quota.
4
4
 
5
5
  ## Thanks
6
6
 
@@ -22,17 +22,13 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
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
25
  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
26
 
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
27
+ Provincias.find(28) => #<Provincia: @id=28, @name="Madrid">
28
+ Provincias.find_by_name('Palmas, Las') => #<Provincia: @id=35, @name="Palmas, Las">
29
+ Provincias.find_by_name('wombat') => nil
30
+ Provincias.all => [...] # An array of Provincia instances
31
+ Provincias.all_for_select => [...] # An array in form [name, id] to use in your select helpers in Rails
36
32
 
37
33
  ## Contributing
38
34
 
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'provincias'
@@ -1,3 +1,3 @@
1
1
  module Provincias
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/provincias.rb CHANGED
@@ -2,90 +2,91 @@
2
2
  require "provincias/version"
3
3
 
4
4
  module Provincias
5
- class Provincia
6
-
7
- attr_reader :id, :name
8
5
 
9
- def initialize(hash)
10
- @id = hash[:id]
11
- @name = hash[:name]
6
+ def self.find(id)
7
+ @@provincias.each do |p|
8
+ return Provincia.new(p) if id == p[:id]
12
9
  end
10
+ nil
11
+ end
13
12
 
14
- def self.find(id)
15
- @@provincias.each do |p|
16
- return Provincia.new(p) if id == p[:id]
17
- end
18
- nil
13
+ def self.find_by_name(name)
14
+ @@provincias.each do |p|
15
+ return Provincia.new(p) if name == p[:name]
19
16
  end
17
+ nil
18
+ end
20
19
 
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
20
+ def self.all
21
+ @@provincias.map { |p| Provincia.new(p) }
22
+ end
27
23
 
28
- def self.all
29
- @@provincias.map { |p| Provincia.new(p) }
30
- end
24
+ def self.all_for_select
25
+ @@provincias.map { |p| [p[:name], p[:id]] }
26
+ end
31
27
 
32
- def self.all_for_select
33
- @@provincias.map { |p| [p[:name], p[:id]] }
34
- end
28
+ class Provincia
29
+
30
+ attr_reader :id, :name
35
31
 
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'}]
32
+ def initialize(hash)
33
+ @id = hash[:id]
34
+ @name = hash[:name]
35
+ end
90
36
  end
91
- end
37
+
38
+ private
39
+ @@provincias = [
40
+ {:id => 1, :name => 'Álava'},
41
+ {:id => 2, :name => 'Albacete'},
42
+ {:id => 3, :name => 'Alicante'},
43
+ {:id => 4, :name => 'Almería'},
44
+ {:id => 5, :name => 'Avila'},
45
+ {:id => 6, :name => 'Badajoz'},
46
+ {:id => 7, :name => 'Illes Baleares'},
47
+ {:id => 8, :name => 'Barcelona'},
48
+ {:id => 9, :name => 'Burgos'},
49
+ {:id => 10, :name => 'Cáceres'},
50
+ {:id => 11, :name => 'Cádiz'},
51
+ {:id => 12, :name => 'Cástellón'},
52
+ {:id => 13, :name => 'Ciudad Real'},
53
+ {:id => 14, :name => 'Córdoba'},
54
+ {:id => 15, :name => 'Coruña, A'},
55
+ {:id => 16, :name => 'Cuenca'},
56
+ {:id => 17, :name => 'Girona'},
57
+ {:id => 18, :name => 'Granada'},
58
+ {:id => 19, :name => 'Guadalajara'},
59
+ {:id => 20, :name => 'Guipuzcoa'},
60
+ {:id => 21, :name => 'Huelva'},
61
+ {:id => 22, :name => 'Huesca'},
62
+ {:id => 23, :name => 'Jaén'},
63
+ {:id => 24, :name => 'León'},
64
+ {:id => 25, :name => 'Lleida'},
65
+ {:id => 26, :name => 'Rioja, La'},
66
+ {:id => 27, :name => 'Lugo'},
67
+ {:id => 28, :name => 'Madrid'},
68
+ {:id => 29, :name => 'Málaga'},
69
+ {:id => 30, :name => 'Murcia'},
70
+ {:id => 31, :name => 'Navarra'},
71
+ {:id => 32, :name => 'Ourense'},
72
+ {:id => 33, :name => 'Asturias'},
73
+ {:id => 34, :name => 'Palencia'},
74
+ {:id => 35, :name => 'Palmas, Las'},
75
+ {:id => 36, :name => 'Pontevedra'},
76
+ {:id => 37, :name => 'Salamanca'},
77
+ {:id => 38, :name => 'Santa Cruz de Tenerife'},
78
+ {:id => 39, :name => 'Cantabria'},
79
+ {:id => 40, :name => 'Segovia'},
80
+ {:id => 41, :name => 'Sevilla'},
81
+ {:id => 42, :name => 'Soria'},
82
+ {:id => 43, :name => 'Tarragona'},
83
+ {:id => 44, :name => 'Teruel'},
84
+ {:id => 45, :name => 'Toledo'},
85
+ {:id => 46, :name => 'Valencia'},
86
+ {:id => 47, :name => 'Valladolid'},
87
+ {:id => 48, :name => 'Vizcaya'},
88
+ {:id => 49, :name => 'Zamora'},
89
+ {:id => 50, :name => 'Zaragoza'},
90
+ {:id => 51, :name => 'Ceuta'},
91
+ {:id => 52, :name => 'Melilla'}]
92
+ end
data/provincias.gemspec CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/provincias/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Javier Toledo"]
6
6
  gem.email = ["javier@theagilemonkeys.com"]
7
- gem.description = %q{Provides a Provincia class to search for and use spanish province in your apps.}
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.}
7
+ gem.description = %q{Provides a way to easily manage spanish provinces in your apps without creating additional tables in your database.}
8
+ gem.summary = %q{Stop storing spanish provinces in a static table in your database. Use this gem and reclaim a few bytes of your storage quota.}
9
9
  gem.homepage = "https://github.com/agilemonkeys/provincias"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: provincias
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,8 +11,8 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-06-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: Provides a Provincia class to search for and use spanish province in
15
- your apps.
14
+ description: Provides a way to easily manage spanish provinces in your apps without
15
+ creating additional tables in your database.
16
16
  email:
17
17
  - javier@theagilemonkeys.com
18
18
  executables: []
@@ -24,6 +24,7 @@ files:
24
24
  - LICENSE
25
25
  - README.md
26
26
  - Rakefile
27
+ - init.rb
27
28
  - lib/provincias.rb
28
29
  - lib/provincias/version.rb
29
30
  - provincias.gemspec
@@ -51,7 +52,6 @@ rubygems_version: 1.8.24
51
52
  signing_key:
52
53
  specification_version: 3
53
54
  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.
55
+ gem and reclaim a few bytes of your storage quota.
56
56
  test_files: []
57
57
  has_rdoc: