mexican-states 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/CODE_OF_CONDUCT.md +49 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +43 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/generators/mexican/states/install_generator.rb +62 -0
  13. data/lib/generators/templates/active_record/models/city.rb +8 -0
  14. data/lib/generators/templates/active_record/models/neighborhood.rb +9 -0
  15. data/lib/generators/templates/active_record/models/state.rb +6 -0
  16. data/lib/generators/templates/migrations/create_cities.rb +11 -0
  17. data/lib/generators/templates/migrations/create_neighborhoods.rb +12 -0
  18. data/lib/generators/templates/migrations/create_states.rb +9 -0
  19. data/lib/mexican/states/version.rb +5 -0
  20. data/lib/mexican/states.rb +7 -0
  21. data/lib/support/Aguascalientes-Table 1.csv +1361 -0
  22. data/lib/support/Baja_California-Table 1.csv +2338 -0
  23. data/lib/support/Baja_California_Sur-Table 1.csv +969 -0
  24. data/lib/support/Campeche-Table 1.csv +1312 -0
  25. data/lib/support/Chiapas-Table 1.csv +7537 -0
  26. data/lib/support/Chihuahua-Table 1.csv +9450 -0
  27. data/lib/support/Coahuila_de_Zaragoza-Table 1.csv +3890 -0
  28. data/lib/support/Colima-Table 1.csv +823 -0
  29. data/lib/support/Distrito_Federal-Table 1.csv +1930 -0
  30. data/lib/support/Durango-Table 1.csv +7083 -0
  31. data/lib/support/Guanajuato-Table 1.csv +9926 -0
  32. data/lib/support/Guerrero-Table 1.csv +4830 -0
  33. data/lib/support/Hidalgo-Table 1.csv +6125 -0
  34. data/lib/support/Jalisco-Table 1.csv +5717 -0
  35. data/lib/support/Michoac/303/241n_de_Ocampo-Table 1.csv" +10248 -0
  36. data/lib/support/Morelos-Table 1.csv +1774 -0
  37. data/lib/support/M/303/251xico-Table 1.csv" +8237 -0
  38. data/lib/support/Nayarit-Table 1.csv +2013 -0
  39. data/lib/support/Nuevo_Le/303/263n-Table 1.csv" +4764 -0
  40. data/lib/support/Oaxaca-Table 1.csv +6104 -0
  41. data/lib/support/Puebla-Table 1.csv +5206 -0
  42. data/lib/support/Quer/303/251taro-Table 1.csv" +3184 -0
  43. data/lib/support/Quintana_Roo-Table 1.csv +1204 -0
  44. data/lib/support/San_Luis_Potos/303/255-Table 1.csv" +6069 -0
  45. data/lib/support/Sinaloa-Table 1.csv +4009 -0
  46. data/lib/support/Sonora-Table 1.csv +9410 -0
  47. data/lib/support/StatesInfo.zip +0 -0
  48. data/lib/support/Tabasco-Table 1.csv +2721 -0
  49. data/lib/support/Tamaulipas-Table 1.csv +3198 -0
  50. data/lib/support/Tlaxcala-Table 1.csv +1522 -0
  51. data/lib/support/Veracruz_de_Ignacio_de_la_Llave-Table 1.csv +8735 -0
  52. data/lib/support/Yucat/303/241n-Table 1.csv" +1870 -0
  53. data/lib/support/Zacatecas-Table 1.csv +1783 -0
  54. data/mexican-states.gemspec +33 -0
  55. data/spec/mexican/states_spec.rb +11 -0
  56. data/spec/spec_helper.rb +2 -0
  57. 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
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
@@ -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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mexican-states.gemspec
4
+ gemspec
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
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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,8 @@
1
+ # City model
2
+ # name:string
3
+ # state_id:integer
4
+ class City < ActiveRecord::Base
5
+ validates :name, presence: true
6
+ belongs_to :state
7
+ has_many :neighborhoods
8
+ end
@@ -0,0 +1,9 @@
1
+ # Neighborhood model
2
+ # name:string
3
+ # zip_code:string
4
+ # city_id:integer
5
+ class Neighborhood < ActiveRecord::Base
6
+ validates :name, :zip_code, presence: true
7
+ belongs_to :state
8
+ has_many :neighborhoods
9
+ end
@@ -0,0 +1,6 @@
1
+ # State model
2
+ # name:string
3
+ class State < ActiveRecord::Base
4
+ validates :name, presence: true
5
+ has_many :cities
6
+ end
@@ -0,0 +1,11 @@
1
+ # Create city migration file
2
+ class CreateCities < ActiveRecord::Migration
3
+ def change
4
+ create_table :cities do |t|
5
+ t.string :name
6
+ t.references :state, index: true, foreign_key: true
7
+
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ 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
@@ -0,0 +1,9 @@
1
+ # Create state migration file
2
+ class CreateStates < ActiveRecord::Migration
3
+ def change
4
+ create_table :states do |t|
5
+ t.string :name
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Mexican
2
+ module States
3
+ VERSION = '0.1.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'mexican/states/version'
2
+
3
+ module Mexican
4
+ # States module
5
+ module States
6
+ end
7
+ end