welike-geography 0.0.2

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,53 @@
1
+ = Geography Rails Plugin
2
+
3
+ == Description
4
+
5
+ This is a plugin for Rails that provides common geography-related classes, helpers, and up-to-date data, such
6
+ as Continent, Country, State, and ZipCode.
7
+
8
+ == Installation
9
+
10
+ [code]
11
+ $ sudo gem install welike-geography --source http://gems.github.com
12
+ $ script/generate geography
13
+ [/code]
14
+
15
+ == Classes
16
+
17
+ * Continent
18
+ * Country
19
+ * State
20
+ * County
21
+ * PostalCode
22
+
23
+ == Data Sources
24
+
25
+ All of the data sources (including some that are not currently in use) are listed on the [[Data Sources]] page on the wiki. The
26
+ decision on which data sources to use were solely based on simplicity of data retrieval and parsing. In the future, based on user
27
+ feedback, we can use alternative data sources that might be more precise or more up-to-date.
28
+
29
+ === Continent
30
+
31
+ * MaxMind
32
+
33
+ === Country
34
+
35
+ * MaxMind
36
+
37
+ == Author
38
+
39
+ Kevin Elliott is the President of WeLike LLC, a company building web and phone applications that help people find
40
+ the things they'll love. Besides spending a lot of time making his company successful and learning new technologies,
41
+ Kevin likes to give back to the community that gave him so much.
42
+
43
+ Kevin Elliott - mailto:kevin@welikeinc.com or mailto:kevin@phunc.com
44
+
45
+ Company - http://www.welikeinc.com
46
+
47
+ Blog - http://kevinelliott.net/blogs/entrepreneurial
48
+
49
+ http://twitter.com/kevinelliott
50
+
51
+
52
+ Copyright (c) 2009 WeLike, LLC, released under the MIT license
53
+
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = Geography Rails Plugin
2
+
3
+ == Description
4
+
5
+ This is a plugin for Rails that provides common geography-related classes, helpers, and up-to-date data, such
6
+ as Continent, Country, State, and ZipCode.
7
+
8
+ == Installation
9
+
10
+ [code]
11
+ $ sudo gem install welike-geography --source http://gems.github.com
12
+ $ script/generate geography
13
+ [/code]
14
+
15
+ == Classes
16
+
17
+ * Continent
18
+ * Country
19
+ * State
20
+ * County
21
+ * PostalCode
22
+
23
+ == Data Sources
24
+
25
+ All of the data sources (including some that are not currently in use) are listed on the [[Data Sources]] page on the wiki. The
26
+ decision on which data sources to use were solely based on simplicity of data retrieval and parsing. In the future, based on user
27
+ feedback, we can use alternative data sources that might be more precise or more up-to-date.
28
+
29
+ === Continent
30
+
31
+ * MaxMind
32
+
33
+ === Country
34
+
35
+ * MaxMind
36
+
37
+ == Author
38
+
39
+ Kevin Elliott is the President of WeLike LLC, a company building web and phone applications that help people find
40
+ the things they'll love. Besides spending a lot of time making his company successful and learning new technologies,
41
+ Kevin likes to give back to the community that gave him so much.
42
+
43
+ Kevin Elliott - mailto:kevin@welikeinc.com or mailto:kevin@phunc.com
44
+
45
+ Company - http://www.welikeinc.com
46
+
47
+ Blog - http://kevinelliott.net/blogs/entrepreneurial
48
+
49
+ http://twitter.com/kevinelliott
50
+
51
+
52
+ Copyright (c) 2009 WeLike, LLC, released under the MIT license
53
+
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gemspec|
9
+ gemspec.name = "geography"
10
+ gemspec.summary = "Commonly needed geography classes, migrations, and helpers"
11
+ gemspec.email = "kevin@welikeinc.com"
12
+ gemspec.homepage = "http://github.com/welike/geography"
13
+ gemspec.description = "TODO"
14
+ gemspec.authors = ["Kevin Elliott"]
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ end
19
+
20
+ desc 'Default: run unit tests.'
21
+ task :default => :test
22
+
23
+ desc 'Test the geography plugin.'
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = true
29
+ end
30
+
31
+ desc 'Generate documentation for the geography plugin.'
32
+ Rake::RDocTask.new(:rdoc) do |rdoc|
33
+ rdoc.rdoc_dir = 'rdoc'
34
+ rdoc.title = 'Geography'
35
+ rdoc.options << '--line-numbers' << '--inline-source'
36
+ rdoc.rdoc_files.include('README')
37
+ rdoc.rdoc_files.include('lib/**/*.rb')
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,24 @@
1
+ class GeographyGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.template 'models/continent.rb', 'app/models/continent.rb'
5
+ m.template 'models/country.rb', 'app/models/country.rb'
6
+ m.template 'models/state.rb', 'app/models/state.rb'
7
+ m.template 'models/region.rb', 'app/models/region.rb'
8
+ m.template 'models/county.rb', 'app/models/county.rb'
9
+
10
+ m.migration_template 'migrations/continents.rb', "db/migrate", :migration_file_name => "create_continents"
11
+ m.migration_template 'migrations/countries.rb', "db/migrate", :migration_file_name => "create_countries"
12
+ m.migration_template 'migrations/states.rb', "db/migrate", :migration_file_name => "create_states"
13
+ m.migration_template 'migrations/regions.rb', "db/migrate", :migration_file_name => "create_regions"
14
+ m.migration_template 'migrations/counties.rb', "db/migrate", :migration_file_name => "create_counties"
15
+ end
16
+ end
17
+
18
+ private
19
+ def custom_file_name
20
+ custom_name = class_name.underscore.downcase
21
+ custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names
22
+ end
23
+
24
+ end
@@ -0,0 +1,14 @@
1
+ class CreateContinents < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :continents do |t|
4
+ t.string :name, :null => false
5
+ t.string :description, :null => true
6
+ t.string :iso_3166_code, :null => false
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :continents
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ class CreateCounties < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :counties do |t|
4
+ t.string :name
5
+ t.string :description
6
+ t.integer :country_id
7
+ t.string :fips_state_name
8
+ t.string :fips_state_numeric_code
9
+ t.string :fips_county_numeric_code
10
+ t.string :fips_county_name
11
+ t.string :fips_class_code
12
+ t.float :latitude
13
+ t.float :longitude
14
+
15
+ t.timestamps
16
+ end
17
+ end
18
+
19
+ def self.down
20
+ drop_table :counties
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ class CreateCountries < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :countries do |t|
4
+ t.string :name
5
+ t.string :description
6
+ t.string :iso_3166_continent_alpha_code
7
+ t.integer :continent_id
8
+ t.string :iso_3166_1_alpha_2
9
+ t.string :iso_3166_1_alpha_3
10
+ t.string :iso_3166_1_numeric_code
11
+ t.string :tld
12
+ t.string :fips_10_4_alpha_code
13
+
14
+ t.timestamps
15
+ end
16
+ end
17
+
18
+ def self.down
19
+ drop_table :countries
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ class CreateRegions < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :regions do |t|
4
+ t.string :name
5
+ t.string :description
6
+ t.integer :county_id
7
+ t.integer :state_id
8
+ t.integer :country_id
9
+ t.boolean :active, :default => false
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ Region.create(:name => 'San Francisco Bay Area',
15
+ :description => 'Home of the 49ers, Silicon Valley, and redwood trees!',
16
+ :active => true)
17
+ end
18
+
19
+ def self.down
20
+ drop_table :regions
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ class CreateStates < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :states do |t|
4
+ t.string :name
5
+ t.string :official_name
6
+ t.string :description
7
+ t.string :iso_3166_2_alpha_code
8
+ t.string :fips_5_2_numeric_code
9
+ t.string :fips_5_2_alpha_code
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table :states
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class Continent < ActiveRecord::Base
2
+ has_many :countries
3
+ end
@@ -0,0 +1,4 @@
1
+ class Country < ActiveRecord::Base
2
+ belongs_to :continent
3
+ has_many :states
4
+ end
@@ -0,0 +1,2 @@
1
+ class County < ActiveRecord::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class Region < ActiveRecord::Base
2
+ belongs_to :country
3
+ belongs_to :state
4
+ end
@@ -0,0 +1,4 @@
1
+ class State < ActiveRecord::Base
2
+ belongs_to :country
3
+ has_many :regions
4
+ end
data/geography.gemspec ADDED
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{geography}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kevin Elliott"]
12
+ s.date = %q{2009-09-14}
13
+ s.description = %q{TODO}
14
+ s.email = %q{kevin@welikeinc.com}
15
+ s.extra_rdoc_files = [
16
+ "README",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "MIT-LICENSE",
21
+ "README",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "generators/geography/geography_generator.rb",
26
+ "generators/geography/templates/migrations/continents.rb",
27
+ "generators/geography/templates/migrations/counties.rb",
28
+ "generators/geography/templates/migrations/countries.rb",
29
+ "generators/geography/templates/migrations/regions.rb",
30
+ "generators/geography/templates/migrations/states.rb",
31
+ "generators/geography/templates/models/continent.rb",
32
+ "generators/geography/templates/models/country.rb",
33
+ "generators/geography/templates/models/county.rb",
34
+ "generators/geography/templates/models/region.rb",
35
+ "generators/geography/templates/models/state.rb",
36
+ "geography.gemspec",
37
+ "init.rb",
38
+ "install.rb",
39
+ "lib/geography.rb",
40
+ "lib/geography/data_loaders.rb",
41
+ "lib/geography/data_loaders/countries.rb",
42
+ "rails/init.rb",
43
+ "tasks/geography_tasks.rake",
44
+ "test/geography_test.rb",
45
+ "test/test_helper.rb",
46
+ "uninstall.rb"
47
+ ]
48
+ s.has_rdoc = true
49
+ s.homepage = %q{http://github.com/welike/geography}
50
+ s.rdoc_options = ["--charset=UTF-8"]
51
+ s.require_paths = ["lib"]
52
+ s.rubygems_version = %q{1.3.1}
53
+ s.summary = %q{Commonly needed geography classes, migrations, and helpers}
54
+ s.test_files = [
55
+ "test/geography_test.rb",
56
+ "test/test_helper.rb"
57
+ ]
58
+
59
+ if s.respond_to? :specification_version then
60
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
61
+ s.specification_version = 2
62
+
63
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
64
+ else
65
+ end
66
+ else
67
+ end
68
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ # Include hook code here
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,31 @@
1
+ class Geography::DataLoaders::Countries
2
+ def self.load_from_wikipedia_file(filename)
3
+ count_updated = 0
4
+ count_new = 0
5
+
6
+ data = File.open(filename).readlines
7
+ data.each do |line|
8
+ items = line.split(' ', 5)
9
+ c = Country.find_by_name(items[4].chomp)
10
+ if c
11
+ #puts "Country '#{items[4].chomp}' already exists!"
12
+ c.continent = Continent.find_by_iso_3166_code(items[0])
13
+ c.save
14
+ count_updated += 1
15
+ else
16
+ #puts "Creating new country '#{items[4].chomp}'"
17
+ c = Country.create(:name => items[4].chomp,
18
+ :iso_3166_continent_alpha_code => items[0],
19
+ :iso_3166_1_alpha_2 => items[1],
20
+ :iso_3166_1_alpha_3 => items[2],
21
+ :iso_3166_1_numeric_code => items[3]
22
+ )
23
+ c.continent = Continent.find_by_iso_3166_code(items[0])
24
+ c.save
25
+ count_new += 1
26
+ end
27
+ end
28
+
29
+ puts "Load stats: Countries, #{count_new} new, #{count_updated} updated"
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ require "geography/data_loaders/countries"
2
+
3
+ class Geography::DataLoaders
4
+ end
data/lib/geography.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "geography/data_loaders"
2
+
3
+ %w{ models }.each do |dir|
4
+ path = File.join(File.dirname(__FILE__), 'app', dir)
5
+ $LOAD_PATH << path
6
+ ActiveSupport::Dependencies.load_paths << path
7
+ ActiveSupport::Dependencies.load_once_paths.delete(path)
8
+ end
9
+
10
+ class Geography
11
+ end
12
+
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'geography'
@@ -0,0 +1,8 @@
1
+ namespace :geo do
2
+ namespace :load do
3
+ desc "Load countries from a file"
4
+ task :countries => :environment do
5
+ Geography::DataLoaders::Countries.load_from_wikipedia_file('db/raw/Wikipedia-countries_for_continents.tsv')
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class GeographyTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: welike-geography
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Elliott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: TODO
17
+ email: kevin@welikeinc.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - README.rdoc
25
+ files:
26
+ - MIT-LICENSE
27
+ - README
28
+ - README.rdoc
29
+ - Rakefile
30
+ - VERSION
31
+ - generators/geography/geography_generator.rb
32
+ - generators/geography/templates/migrations/continents.rb
33
+ - generators/geography/templates/migrations/counties.rb
34
+ - generators/geography/templates/migrations/countries.rb
35
+ - generators/geography/templates/migrations/regions.rb
36
+ - generators/geography/templates/migrations/states.rb
37
+ - generators/geography/templates/models/continent.rb
38
+ - generators/geography/templates/models/country.rb
39
+ - generators/geography/templates/models/county.rb
40
+ - generators/geography/templates/models/region.rb
41
+ - generators/geography/templates/models/state.rb
42
+ - geography.gemspec
43
+ - init.rb
44
+ - install.rb
45
+ - lib/geography.rb
46
+ - lib/geography/data_loaders.rb
47
+ - lib/geography/data_loaders/countries.rb
48
+ - rails/init.rb
49
+ - tasks/geography_tasks.rake
50
+ - test/geography_test.rb
51
+ - test/test_helper.rb
52
+ - uninstall.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/welike/geography
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.2.0
76
+ signing_key:
77
+ specification_version: 2
78
+ summary: Commonly needed geography classes, migrations, and helpers
79
+ test_files:
80
+ - test/geography_test.rb
81
+ - test/test_helper.rb