geonames_local 1.0.0 → 2.0.0
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/Gemfile +1 -0
- data/README.rdoc +11 -25
- data/bin/geonames +2 -1
- data/geonames.yml +3 -3
- data/lib/geonames_local.rb +5 -10
- data/lib/geonames_local/cli.rb +31 -54
- data/lib/geonames_local/data/dump.rb +24 -11
- data/lib/geonames_local/data/shp.rb +1 -1
- data/lib/geonames_local/features/spot.rb +8 -33
- data/lib/geonames_local/geonames.rb +0 -5
- data/lib/geonames_local/models/mongodb.rb +157 -39
- data/lib/geonames_local/version.rb +1 -1
- data/spec/geonames_local/adapters/{postgres_spec.rb → postgis_spec.rb} +2 -2
- data/spec/geonames_local/features/spot_spec.rb +5 -7
- data/spec/geonames_local/models/{mongo_spec.rb → mongodb_spec.rb} +12 -9
- data/spec/geonames_local/models/postgis_spec.rb +73 -0
- data/spec/geonames_local_spec.rb +1 -0
- data/spec/spec_ar_helper.rb +96 -96
- data/spec/spec_helper.rb +1 -1
- metadata +8 -16
- data/lib/geonames_ar.rb +0 -12
- data/lib/geonames_cli.rb +0 -14
- data/lib/geonames_local/adapters/mongodb.rb +0 -109
- data/lib/geonames_local/adapters/postgres.rb +0 -108
- data/lib/geonames_local/adapters/tokyo.rb +0 -109
- data/lib/geonames_local/data/sync.rb +0 -74
- data/spec/geonames_local/models/ar_spec.rb +0 -73
- data/spec/spec_mongo_helper.rb +0 -6
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/geonames_local/adapters/
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/geonames_local/adapters/postgis')
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Postgis do
|
5
5
|
|
6
6
|
def wipe_db
|
7
7
|
end
|
@@ -156,8 +156,7 @@ describe Spot do
|
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should parse province" do
|
159
|
-
|
160
|
-
spot.province.should eql("C")
|
159
|
+
spot.province.should eql("06")
|
161
160
|
end
|
162
161
|
|
163
162
|
it "should parse pop" do
|
@@ -200,7 +199,7 @@ describe Spot do
|
|
200
199
|
|
201
200
|
it "should parse province" do
|
202
201
|
pending
|
203
|
-
spot.province.should eql("
|
202
|
+
spot.province.should eql("18")
|
204
203
|
end
|
205
204
|
|
206
205
|
it "should parse pop" do
|
@@ -212,7 +211,7 @@ describe Spot do
|
|
212
211
|
|
213
212
|
describe "Parsing Zip" do
|
214
213
|
|
215
|
-
let(:spot) { Geonames::Spot.new("BR\t76375-000\tHidrolina\tGoias\t29\t\t5209804\t\t-14.7574\t-49.3596\t\n", :zip) }
|
214
|
+
let(:spot) { Geonames::Spot.new("BR\t76375-000\tHidrolina\tGoias\t29\t\t5209804\t\t\t-14.7574\t-49.3596\t\n", :zip) }
|
216
215
|
|
217
216
|
it "should parse zip oO" do
|
218
217
|
spot.zip.should eql("76375")
|
@@ -223,7 +222,7 @@ describe Spot do
|
|
223
222
|
end
|
224
223
|
|
225
224
|
it "should parse code" do
|
226
|
-
spot.code.should eql("
|
225
|
+
spot.code.should eql("29")
|
227
226
|
end
|
228
227
|
|
229
228
|
it "should parse geoid integer" do
|
@@ -247,7 +246,7 @@ describe Spot do
|
|
247
246
|
|
248
247
|
describe "From Hash" do
|
249
248
|
|
250
|
-
let(:spot) { Spot.from_hash({"id" => 9, "name" => "Sao Rock", "geom" => [15,15], "kind" => "
|
249
|
+
let(:spot) { Spot.from_hash({"id" => 9, "name" => "Sao Rock", "geom" => [15,15], "kind" => "city", "country" => "BR", "gid" => 13232, "tz" => "America/Foo", "ascii" => "Rock"}) }
|
251
250
|
|
252
251
|
it "should be an spot" do
|
253
252
|
spot.should be_instance_of Spot
|
@@ -302,4 +301,3 @@ end
|
|
302
301
|
# "3165361\tToscana\tToscana\tTaskana,Toscan-a,Toscana,Toscane,Toscann-a,Toskana,Toskania,Toskanio,Toskansko,Toskánsko,Toskāna,Toszkana,Toszkána,Tuscany,Tuschena,Tuschèna,Tuscia,toseukana ju,tosukana zhou,tuo si ka na,twsqnh,Таскана,Тоскана,טוסקנה,تسکانہ,ტოსკანა,トスカーナ州,托斯卡纳,토스카나 주\t43.4166667\t11.0\tA\tADM1\tIT\t\t16\t\t\t\t3718210\t\t249\tEurope/Rome\t2010-01-17\n"
|
303
302
|
# "3169778\tRegione Puglia\tRegione Puglia\tApulia,Apulie,Apulien,Apulië,Pouilles,Puglia\t41.25\t16.25\tA\tADM1\tIT\t\t13\t\t\t\t4021957\t\t95\tEurope/Rome\t2009-03-11\n"
|
304
303
|
# "3170831\tRegione Piemonte\tRegione Piemonte\tPedemons,Pedemontium,Piamonte,Piedmont,Piemont,Piemonte,Piémont,Piëmont,Regione Piemonte\t45.0\t8.0\tA\tADM1\tIT\t\t12\t\t\t\t4294081\t\t185\tEurope/Rome\t2008-08-18\n"
|
305
|
-
|
@@ -1,20 +1,22 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require File.
|
3
|
-
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
require 'geonames_local/models/mongodb'
|
5
|
+
include Models::Mongo
|
4
6
|
|
5
7
|
describe "City" do
|
6
8
|
|
7
|
-
before(:all) do
|
8
|
-
|
9
|
-
|
10
|
-
end
|
9
|
+
# before(:all) do
|
10
|
+
# Models::Mongo::City.insert("cities", {"id" => 9, "name" => "Sao Paulo", "geom" => [15,15]})
|
11
|
+
# Models::Mongo::City.insert("cities", {"id" => 66, "name" => "Rock City", "geom" => [2,3]})
|
12
|
+
# end
|
11
13
|
|
12
14
|
after(:all) do
|
13
|
-
Mongodb.new({:dbname => "
|
15
|
+
Mongodb.new({:dbname => "geonames_test"}).purge
|
14
16
|
end
|
15
17
|
|
16
18
|
it "should set a collection name" do
|
17
|
-
|
19
|
+
City.collection.should eql("cities")
|
18
20
|
end
|
19
21
|
|
20
22
|
it "should find all cities" do
|
@@ -34,6 +36,7 @@ describe "City" do
|
|
34
36
|
end
|
35
37
|
|
36
38
|
it "should find by name" do
|
37
|
-
|
39
|
+
City.find_by_name("rock").first.name.should eql("Rock City")
|
38
40
|
end
|
41
|
+
|
39
42
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# require File.expand_path(File.dirname(__FILE__) + '/../../spec_ar_helper')
|
3
|
+
# module Geonames
|
4
|
+
# module Models
|
5
|
+
# module AR
|
6
|
+
# class User < ActiveRecord::Base
|
7
|
+
# belongs_to :city
|
8
|
+
# end
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
|
13
|
+
# def brasil
|
14
|
+
# Models::AR::Country.find_or_create_by_name(:name => "Brazil", :abbr => "BR")
|
15
|
+
# end
|
16
|
+
|
17
|
+
# describe "Country" do
|
18
|
+
|
19
|
+
# it "should create countries" do
|
20
|
+
# Models::AR::Country.create(:name => "Chad", :abbr => "TD").should be_valid
|
21
|
+
# end
|
22
|
+
|
23
|
+
# it "should write to db" do
|
24
|
+
# lambda do
|
25
|
+
# Models::AR::Country.create(:name => "Itália", :abbr => "IT")
|
26
|
+
# end.should change(Models::AR::Country, :count).by(1)
|
27
|
+
# end
|
28
|
+
|
29
|
+
# end
|
30
|
+
|
31
|
+
# describe "Province" do
|
32
|
+
|
33
|
+
# it "should be a class instance of ar" do
|
34
|
+
# Models::AR::Province.new.should be_instance_of Models::AR::Province
|
35
|
+
# end
|
36
|
+
|
37
|
+
# it "should create" do
|
38
|
+
# Models::AR::Province.create(:name => "Chadland", :country => brasil).should be_valid
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
# describe "City" do
|
43
|
+
|
44
|
+
# it "should be a class instance of ar" do
|
45
|
+
# Models::AR::City.new.should be_instance_of Models::AR::City
|
46
|
+
# end
|
47
|
+
|
48
|
+
# it "should create" do
|
49
|
+
# Models::AR::City.create(:name => "Chadland", :country => brasil).should be_valid
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
# # DatabaseCleaner.clean
|
53
|
+
|
54
|
+
# describe "Active Record Stuff" do
|
55
|
+
|
56
|
+
# before do
|
57
|
+
# # DatabaseCleaner.clean
|
58
|
+
# @br ||= brasil
|
59
|
+
# Models::AR::City.create!("name" => "São Tomé", "geom" => [15,15], :country => @br)
|
60
|
+
# Models::AR::City.create!("name" => "Rock CIty", "geom" => [18,16], :country => @br)
|
61
|
+
# end
|
62
|
+
|
63
|
+
# it "should record" do
|
64
|
+
# Models::AR::City.count.should eql(2)
|
65
|
+
# end
|
66
|
+
|
67
|
+
# it "should create" do
|
68
|
+
# user = Models::AR::User.new(:name => "Defendor")
|
69
|
+
# user.city = Models::AR::City.first
|
70
|
+
# user.save
|
71
|
+
# Models::AR::User.first.city.name.should eql("São Tomé")
|
72
|
+
# end
|
73
|
+
# end
|
data/spec/geonames_local_spec.rb
CHANGED
data/spec/spec_ar_helper.rb
CHANGED
@@ -1,96 +1,96 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require 'rspec'
|
4
|
-
require 'rspec/autorun'
|
5
|
-
require 'active_record'
|
6
|
-
require 'postgis_adapter'
|
7
|
-
require 'database_cleaner'
|
8
|
-
Opt[:db] = { :adapter => "postgresql",
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
require 'geonames_ar'
|
13
|
-
include Geonames::Models
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ActiveRecord::Base.logger = $logger
|
18
|
-
|
19
|
-
begin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
rescue PGError
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
ActiveRecord::Schema.define() do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
RSpec.configure do |c|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
1
|
+
# $LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
# $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
# require 'rspec'
|
4
|
+
# require 'rspec/autorun'
|
5
|
+
# require 'active_record'
|
6
|
+
# require 'postgis_adapter'
|
7
|
+
# require 'database_cleaner'
|
8
|
+
# Opt[:db] = { :adapter => "postgresql",
|
9
|
+
# :database => "geonames_ar",
|
10
|
+
# :username => "postgres",
|
11
|
+
# :password => "" }
|
12
|
+
# require 'geonames_ar'
|
13
|
+
# include Geonames::Models
|
14
|
+
|
15
|
+
# # DatabaseCleaner.strategy = :truncation
|
16
|
+
|
17
|
+
# ActiveRecord::Base.logger = $logger
|
18
|
+
|
19
|
+
# begin
|
20
|
+
# ActiveRecord::Base.establish_connection(Opt[:db])
|
21
|
+
# ActiveRecord::Migration.verbose = false
|
22
|
+
# PG_VERSION = ActiveRecord::Base.connection.select_value("SELECT version()").scan(/PostgreSQL ([\d\.]*)/)[0][0]
|
23
|
+
|
24
|
+
# puts "Running against PostgreSQL #{PG_VERSION}"
|
25
|
+
|
26
|
+
# rescue PGError
|
27
|
+
# puts "Test DB not found, creating one for you..."
|
28
|
+
# `createdb -U postgres geonames_ar -T template_postgis`
|
29
|
+
# puts "Done. Please run spec again."
|
30
|
+
# exit
|
31
|
+
# end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
# ActiveRecord::Schema.define() do
|
36
|
+
|
37
|
+
# create_table :users, :force => true do |t|
|
38
|
+
# t.string :name, :nick, :limit => 100
|
39
|
+
# t.string :email
|
40
|
+
# t.integer :code
|
41
|
+
# t.references :city
|
42
|
+
# end
|
43
|
+
|
44
|
+
# create_table :cities, :force => true do |t|
|
45
|
+
# t.references :country, :null => false
|
46
|
+
# t.references :province
|
47
|
+
# t.string :name, :null => false
|
48
|
+
# t.point :geom, :srid => 4326
|
49
|
+
# t.integer :gid, :zip
|
50
|
+
# end
|
51
|
+
|
52
|
+
# create_table :provinces, :force => true do |t|
|
53
|
+
# t.references :country, :null => false
|
54
|
+
# t.string :name, :null => false
|
55
|
+
# t.string :abbr, :limit => 3
|
56
|
+
# t.integer :gid
|
57
|
+
# end
|
58
|
+
|
59
|
+
# create_table :countries, :force => true do |t|
|
60
|
+
# t.string :name, :limit => 30, :null => false
|
61
|
+
# t.string :abbr, :limit => 2, :null => false
|
62
|
+
# end
|
63
|
+
|
64
|
+
# add_index :cities, :name
|
65
|
+
# add_index :cities, :gid
|
66
|
+
# add_index :cities, :zip
|
67
|
+
# add_index :cities, :country_id
|
68
|
+
# add_index :cities, :province_id
|
69
|
+
# add_index :cities, :geom, :spatial => true
|
70
|
+
# add_index :provinces, :name
|
71
|
+
# add_index :provinces, :abbr
|
72
|
+
# add_index :provinces, :gid
|
73
|
+
# add_index :provinces, :country_id
|
74
|
+
# add_index :countries, :abbr, :unique => true
|
75
|
+
# add_index :countries, :name, :unique => true
|
76
|
+
|
77
|
+
# end
|
78
|
+
|
79
|
+
# RSpec.configure do |c|
|
80
|
+
|
81
|
+
# c.before(:suite) do
|
82
|
+
# DatabaseCleaner.strategy = :transaction
|
83
|
+
# DatabaseCleaner.clean_with(:truncation,
|
84
|
+
# {:except => %w[geography_columns schema_migrations spatial_ref_sys geometry_columns]})
|
85
|
+
# end
|
86
|
+
|
87
|
+
# c.before(:each) do
|
88
|
+
# DatabaseCleaner.start
|
89
|
+
# end
|
90
|
+
|
91
|
+
# c.after(:each) do
|
92
|
+
# DatabaseCleaner.clean
|
93
|
+
# end
|
94
|
+
|
95
|
+
|
96
|
+
# end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geonames_local
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: georuby
|
@@ -45,12 +45,7 @@ files:
|
|
45
45
|
- bin/geonames
|
46
46
|
- geonames.yml
|
47
47
|
- geonames_local.gemspec
|
48
|
-
- lib/geonames_ar.rb
|
49
|
-
- lib/geonames_cli.rb
|
50
48
|
- lib/geonames_local.rb
|
51
|
-
- lib/geonames_local/adapters/mongodb.rb
|
52
|
-
- lib/geonames_local/adapters/postgres.rb
|
53
|
-
- lib/geonames_local/adapters/tokyo.rb
|
54
49
|
- lib/geonames_local/cli.rb
|
55
50
|
- lib/geonames_local/config/codes.yml
|
56
51
|
- lib/geonames_local/config/geonames.sql
|
@@ -58,7 +53,6 @@ files:
|
|
58
53
|
- lib/geonames_local/data/dump.rb
|
59
54
|
- lib/geonames_local/data/export.rb
|
60
55
|
- lib/geonames_local/data/shp.rb
|
61
|
-
- lib/geonames_local/data/sync.rb
|
62
56
|
- lib/geonames_local/features/road.rb
|
63
57
|
- lib/geonames_local/features/spot.rb
|
64
58
|
- lib/geonames_local/features/zone.rb
|
@@ -68,7 +62,7 @@ files:
|
|
68
62
|
- lib/geonames_local/models/tokyo.rb
|
69
63
|
- lib/geonames_local/version.rb
|
70
64
|
- spec/geonames_local/adapters/mongodb_spec.rb
|
71
|
-
- spec/geonames_local/adapters/
|
65
|
+
- spec/geonames_local/adapters/postgis_spec.rb
|
72
66
|
- spec/geonames_local/adapters/tokyo_spec.rb
|
73
67
|
- spec/geonames_local/cli_spec.rb
|
74
68
|
- spec/geonames_local/data/cache_spec.rb
|
@@ -77,12 +71,11 @@ files:
|
|
77
71
|
- spec/geonames_local/features/road_spec.rb
|
78
72
|
- spec/geonames_local/features/spot_spec.rb
|
79
73
|
- spec/geonames_local/features/zone_spec.rb
|
80
|
-
- spec/geonames_local/models/
|
81
|
-
- spec/geonames_local/models/
|
74
|
+
- spec/geonames_local/models/mongodb_spec.rb
|
75
|
+
- spec/geonames_local/models/postgis_spec.rb
|
82
76
|
- spec/geonames_local_spec.rb
|
83
77
|
- spec/spec_ar_helper.rb
|
84
78
|
- spec/spec_helper.rb
|
85
|
-
- spec/spec_mongo_helper.rb
|
86
79
|
- task/benchmark.rb
|
87
80
|
- task/benchmark_cabinet.rb
|
88
81
|
homepage: http://github.com/nofxx/geonames_local
|
@@ -116,7 +109,7 @@ specification_version: 3
|
|
116
109
|
summary: Dump and feed a tokyo local geonames db
|
117
110
|
test_files:
|
118
111
|
- spec/geonames_local/adapters/mongodb_spec.rb
|
119
|
-
- spec/geonames_local/adapters/
|
112
|
+
- spec/geonames_local/adapters/postgis_spec.rb
|
120
113
|
- spec/geonames_local/adapters/tokyo_spec.rb
|
121
114
|
- spec/geonames_local/cli_spec.rb
|
122
115
|
- spec/geonames_local/data/cache_spec.rb
|
@@ -125,10 +118,9 @@ test_files:
|
|
125
118
|
- spec/geonames_local/features/road_spec.rb
|
126
119
|
- spec/geonames_local/features/spot_spec.rb
|
127
120
|
- spec/geonames_local/features/zone_spec.rb
|
128
|
-
- spec/geonames_local/models/
|
129
|
-
- spec/geonames_local/models/
|
121
|
+
- spec/geonames_local/models/mongodb_spec.rb
|
122
|
+
- spec/geonames_local/models/postgis_spec.rb
|
130
123
|
- spec/geonames_local_spec.rb
|
131
124
|
- spec/spec_ar_helper.rb
|
132
125
|
- spec/spec_helper.rb
|
133
|
-
- spec/spec_mongo_helper.rb
|
134
126
|
has_rdoc:
|