mexican-states 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/mexican/states/install_generator.rb +62 -0
- data/lib/generators/templates/active_record/models/city.rb +8 -0
- data/lib/generators/templates/active_record/models/neighborhood.rb +9 -0
- data/lib/generators/templates/active_record/models/state.rb +6 -0
- data/lib/generators/templates/migrations/create_cities.rb +11 -0
- data/lib/generators/templates/migrations/create_neighborhoods.rb +12 -0
- data/lib/generators/templates/migrations/create_states.rb +9 -0
- data/lib/mexican/states/version.rb +5 -0
- data/lib/mexican/states.rb +7 -0
- data/lib/support/Aguascalientes-Table 1.csv +1361 -0
- data/lib/support/Baja_California-Table 1.csv +2338 -0
- data/lib/support/Baja_California_Sur-Table 1.csv +969 -0
- data/lib/support/Campeche-Table 1.csv +1312 -0
- data/lib/support/Chiapas-Table 1.csv +7537 -0
- data/lib/support/Chihuahua-Table 1.csv +9450 -0
- data/lib/support/Coahuila_de_Zaragoza-Table 1.csv +3890 -0
- data/lib/support/Colima-Table 1.csv +823 -0
- data/lib/support/Distrito_Federal-Table 1.csv +1930 -0
- data/lib/support/Durango-Table 1.csv +7083 -0
- data/lib/support/Guanajuato-Table 1.csv +9926 -0
- data/lib/support/Guerrero-Table 1.csv +4830 -0
- data/lib/support/Hidalgo-Table 1.csv +6125 -0
- data/lib/support/Jalisco-Table 1.csv +5717 -0
- data/lib/support/Michoac/303/241n_de_Ocampo-Table 1.csv" +10248 -0
- data/lib/support/Morelos-Table 1.csv +1774 -0
- data/lib/support/M/303/251xico-Table 1.csv" +8237 -0
- data/lib/support/Nayarit-Table 1.csv +2013 -0
- data/lib/support/Nuevo_Le/303/263n-Table 1.csv" +4764 -0
- data/lib/support/Oaxaca-Table 1.csv +6104 -0
- data/lib/support/Puebla-Table 1.csv +5206 -0
- data/lib/support/Quer/303/251taro-Table 1.csv" +3184 -0
- data/lib/support/Quintana_Roo-Table 1.csv +1204 -0
- data/lib/support/San_Luis_Potos/303/255-Table 1.csv" +6069 -0
- data/lib/support/Sinaloa-Table 1.csv +4009 -0
- data/lib/support/Sonora-Table 1.csv +9410 -0
- data/lib/support/StatesInfo.zip +0 -0
- data/lib/support/Tabasco-Table 1.csv +2721 -0
- data/lib/support/Tamaulipas-Table 1.csv +3198 -0
- data/lib/support/Tlaxcala-Table 1.csv +1522 -0
- data/lib/support/Veracruz_de_Ignacio_de_la_Llave-Table 1.csv +8735 -0
- data/lib/support/Yucat/303/241n-Table 1.csv" +1870 -0
- data/lib/support/Zacatecas-Table 1.csv +1783 -0
- data/mexican-states.gemspec +33 -0
- data/spec/mexican/states_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0af320061bb4c942389911210946eda33c948dab
|
4
|
+
data.tar.gz: dc7fd848aa79dba7f1b98d31b1349d14bce36e0a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: adb09069993a09f77ecad30048e148f7d2c4ab08ebf58d8fda02e291d2984e04642f3ecc50f3a7dae23ff61dacab127638c5f77951a24b4e9fbbc75d6b7f306d
|
7
|
+
data.tar.gz: 6088f48493eb9f441965dd2f7d2cec1103612052a32e46f2d461b4ffb3244b2a4cfb7e729e502a7c9995577fd11f9311d76e7fe5991b733f540b97478ae28c28
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at araogaraog@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Carlos Omana
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Mexican::States
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'mexican-states'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mexican-states
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Next, you need to run the generator:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
rails g mexican:states:install
|
25
|
+
```
|
26
|
+
|
27
|
+
This command will create 3 models (State, City and Neighborhood) and it's going to populate the database with the data of each state, city and neighborhood of Mexico.
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
|
+
|
33
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/disblu/mexican-states. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
38
|
+
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
43
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'mexican/states'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'csv'
|
4
|
+
|
5
|
+
module Mexican
|
6
|
+
# States module
|
7
|
+
module States
|
8
|
+
# Install generator class
|
9
|
+
class InstallGenerator < ::Rails::Generators::Base
|
10
|
+
include Rails::Generators::Migration
|
11
|
+
|
12
|
+
source_root File.expand_path('../../../templates/active_record/',
|
13
|
+
__FILE__)
|
14
|
+
|
15
|
+
def self.next_migration_number(path)
|
16
|
+
next_migration_number = current_migration_number(path) + 1
|
17
|
+
ActiveRecord::Migration.next_migration_number(next_migration_number)
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Copy base migrations'
|
21
|
+
def copy_migrations
|
22
|
+
migration_template '../migrations/create_states.rb',
|
23
|
+
'db/migrate/create_states.rb'
|
24
|
+
migration_template '../migrations/create_cities.rb',
|
25
|
+
'db/migrate/create_cities.rb'
|
26
|
+
migration_template '../migrations/create_neighborhoods.rb',
|
27
|
+
'db/migrate/create_neighborhoods.rb'
|
28
|
+
rake 'db:migrate'
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Copy base models'
|
32
|
+
def copy_models
|
33
|
+
copy_file './models/state.rb', 'app/models/state.rb'
|
34
|
+
copy_file './models/city.rb', 'app/models/city.rb'
|
35
|
+
copy_file './models/neighborhood.rb', 'app/models/neighborhood.rb'
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Seed models'
|
39
|
+
def seed_models
|
40
|
+
root = File.expand_path '../../../../support/', __FILE__
|
41
|
+
Dir.glob(root + '/*.csv') do |rb_file|
|
42
|
+
save_datum(File.join(rb_file))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def save_datum(file)
|
49
|
+
CSV.foreach(file) do |row|
|
50
|
+
city_name = row[2]
|
51
|
+
neighborhood_name = row[1]
|
52
|
+
neighborhood_zip_code = row[0]
|
53
|
+
state = State.find_or_create_by(name: row[3])
|
54
|
+
city = City.find_or_create_by(name: city_name, state_id: state.id)
|
55
|
+
Neighborhood.find_or_create_by(name: neighborhood_name,
|
56
|
+
zip_code: neighborhood_zip_code,
|
57
|
+
city_id: city.id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Create neighborhood migration file
|
2
|
+
class CreateNeighborhoods < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :neighborhoods do |t|
|
5
|
+
t.string :name
|
6
|
+
t.string :zip_code
|
7
|
+
t.references :city, index: true, foreign_key: true
|
8
|
+
|
9
|
+
t.timestamps null: false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|