geonames_local 0.3.0 → 0.3.1

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/README.rdoc CHANGED
@@ -13,6 +13,7 @@ To use the adapter, install the corresponding gem:
13
13
  MongoDB => mongodb (optional: mongo_ext)
14
14
  Tokyo => tokyocabinet
15
15
 
16
+ Don't forget to install *unzip* and *curl*.
16
17
 
17
18
  === PostgreSQL
18
19
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/bin/geonames CHANGED
@@ -3,7 +3,7 @@ $VERBOSE = true # -w
3
3
  $KCODE = "u" # -Ku
4
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
5
 
6
- require "geonames_local"
6
+ require "geonames_cli"
7
7
  include Geonames
8
8
 
9
9
  Geonames::CLI.work(ARGV)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{geonames_local}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcos Piccinini"]
12
- s.date = %q{2010-03-20}
12
+ s.date = %q{2010-09-14}
13
13
  s.default_executable = %q{geonames}
14
14
  s.description = %q{Dump and feed a tokyo cabinet for local geonames search}
15
15
  s.email = %q{x@nofxx.com}
@@ -28,7 +28,8 @@ Gem::Specification.new do |s|
28
28
  "bin/geonames",
29
29
  "geonames.yml",
30
30
  "geonames_local.gemspec",
31
- "lib/geonames_ext.rb",
31
+ "lib/geonames_ar.rb",
32
+ "lib/geonames_cli.rb",
32
33
  "lib/geonames_local.rb",
33
34
  "lib/geonames_local/adapters/mongodb.rb",
34
35
  "lib/geonames_local/adapters/postgres.rb",
@@ -45,9 +46,11 @@ Gem::Specification.new do |s|
45
46
  "lib/geonames_local/features/zone.rb",
46
47
  "lib/geonames_local/geonames.rb",
47
48
  "lib/geonames_local/model/city.rb",
48
- "lib/geonames_local/model/conn.rb",
49
49
  "lib/geonames_local/model/country.rb",
50
50
  "lib/geonames_local/model/province.rb",
51
+ "lib/geonames_local/mongo/city.rb",
52
+ "lib/geonames_local/mongo/country.rb",
53
+ "lib/geonames_local/mongo/province.rb",
51
54
  "spec/geonames_local/adapters/mongodb_spec.rb",
52
55
  "spec/geonames_local/adapters/postgres_spec.rb",
53
56
  "spec/geonames_local/adapters/tokyo_spec.rb",
@@ -57,11 +60,13 @@ Gem::Specification.new do |s|
57
60
  "spec/geonames_local/features/road_spec.rb",
58
61
  "spec/geonames_local/features/spot_spec.rb",
59
62
  "spec/geonames_local/features/zone_spec.rb",
60
- "spec/geonames_local/model/city_spec.rb",
63
+ "spec/geonames_local/model/ar_spec.rb",
64
+ "spec/geonames_local/mongo/city_spec.rb",
61
65
  "spec/geonames_local_spec.rb",
62
66
  "spec/spec.opts",
63
- "spec/spec_ext_helper.rb",
67
+ "spec/spec_ar_helper.rb",
64
68
  "spec/spec_helper.rb",
69
+ "spec/spec_mongo_helper.rb",
65
70
  "task/benchmark.rb",
66
71
  "task/benchmark_cabinet.rb"
67
72
  ]
@@ -91,13 +96,15 @@ Have fun because:
91
96
  }
92
97
  s.rdoc_options = ["--charset=UTF-8"]
93
98
  s.require_paths = ["lib"]
94
- s.rubygems_version = %q{1.3.6}
99
+ s.rubygems_version = %q{1.3.7}
95
100
  s.summary = %q{Dump and feed a tokyo local geonames db}
96
101
  s.test_files = [
97
- "spec/spec_helper.rb",
102
+ "spec/spec_ar_helper.rb",
103
+ "spec/spec_helper.rb",
98
104
  "spec/geonames_local/data/shp_spec.rb",
99
105
  "spec/geonames_local/data/cache_spec.rb",
100
- "spec/geonames_local/model/city_spec.rb",
106
+ "spec/geonames_local/model/ar_spec.rb",
107
+ "spec/geonames_local/mongo/city_spec.rb",
101
108
  "spec/geonames_local/cli_spec.rb",
102
109
  "spec/geonames_local/adapters/postgres_spec.rb",
103
110
  "spec/geonames_local/adapters/tokyo_spec.rb",
@@ -105,15 +112,15 @@ Have fun because:
105
112
  "spec/geonames_local/features/spot_spec.rb",
106
113
  "spec/geonames_local/features/zone_spec.rb",
107
114
  "spec/geonames_local/features/road_spec.rb",
108
- "spec/geonames_local_spec.rb",
109
- "spec/spec_ext_helper.rb"
115
+ "spec/spec_mongo_helper.rb",
116
+ "spec/geonames_local_spec.rb"
110
117
  ]
111
118
 
112
119
  if s.respond_to? :specification_version then
113
120
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
114
121
  s.specification_version = 3
115
122
 
116
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
123
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
117
124
  s.add_runtime_dependency(%q<nofxx-georuby>, [">= 1.7.1"])
118
125
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
119
126
  else
@@ -7,7 +7,6 @@ $:.unshift(File.dirname(__FILE__)) unless
7
7
  # Require Libs
8
8
  require 'geonames_local/geonames'
9
9
 
10
- require 'geonames_local/model/conn'
11
10
  require 'geonames_local/model/country'
12
11
  require 'geonames_local/model/province'
13
12
  require 'geonames_local/model/city'
@@ -0,0 +1,13 @@
1
+ #
2
+ # Geonames Local
3
+ #
4
+ $:.unshift(File.dirname(__FILE__)) unless
5
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
6
+
7
+ # Require CLI Stuff
8
+ require 'geonames_local/geonames'
9
+ require 'geonames_local/cli'
10
+ require 'geonames_local/data/shp'
11
+ require 'geonames_local/data/dump'
12
+ require 'geonames_local/data/export'
13
+
@@ -1,13 +1,20 @@
1
1
  #
2
- # Geonames Local
2
+ # Geonames Extension
3
3
  #
4
4
  $:.unshift(File.dirname(__FILE__)) unless
5
5
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
6
6
 
7
- # Require CLI Stuff
7
+ # Require Libs
8
8
  require 'geonames_local/geonames'
9
- require 'geonames_local/cli'
10
- require 'geonames_local/data/shp'
11
- require 'geonames_local/data/dump'
12
- require 'geonames_local/data/export'
13
9
 
10
+ require 'geonames_local/adapters/mongodb'
11
+
12
+ module Geonames
13
+
14
+ Adapter = Geonames::Mongodb.new
15
+
16
+ end
17
+
18
+ require 'geonames_local/mongo/country'
19
+ require 'geonames_local/mongo/province'
20
+ require 'geonames_local/mongo/city'
@@ -9,6 +9,9 @@ module Geonames
9
9
  host, port = params[:host] || "localhost", params[:port] || 27017
10
10
  @conn = Mongo::Connection.new(host, port)
11
11
  @db = @conn.db(params[:dbname] || "geonames")
12
+ if params[:user] || params[:password]
13
+ @db.authenticate(params[:user], params[:password])
14
+ end
12
15
  #purge
13
16
  setup
14
17
  end
@@ -16,7 +19,7 @@ module Geonames
16
19
  def setup
17
20
  for re in RESOURCES
18
21
  coll = @db.collection(re)
19
- coll.create_index(["id", Mongo::ASCENDING], ["gid", Mongo::ASCENDING])
22
+ coll.create_index([["id", Mongo::ASCENDING], ["gid", Mongo::ASCENDING]])
20
23
 
21
24
  # Geometric index, more info:
22
25
  # http://www.mongodb.org/display/DOCS/Geospatial+Indexing
@@ -28,12 +31,16 @@ module Geonames
28
31
  @db.collection(resource.to_s).find().to_a
29
32
  end
30
33
 
34
+ def first(resource)
35
+ @db.collection(resource.to_s).find_one
36
+ end
37
+
31
38
  def find(resource, id, name=nil)
32
39
  @db.collection(resource.to_s).find_one("id" => id)
33
40
  end
34
41
 
35
42
  def find_by_name(resource, name)
36
- do_find(resource, "name" => /#{name}/)
43
+ do_find(resource, "name" => /#{name}/i)
37
44
  end
38
45
 
39
46
  def find_by_zip(resource, zip)
@@ -92,6 +92,10 @@ module Geonames
92
92
  Adapter.all(@coll)
93
93
  end
94
94
 
95
+ def first
96
+ from_hash(Adapter.first(@coll))
97
+ end
98
+
95
99
  def find(id)
96
100
  Adapter.find(@coll, id)
97
101
  end
@@ -1,7 +1,26 @@
1
- class City < Geonames::Spot
1
+ module Geonames
2
+ module Model
3
+ class City < ActiveRecord::Base
4
+ attr_accessor :x, :y, :z
2
5
 
3
- set_coll "cities"
6
+ belongs_to :province
7
+ belongs_to :country
4
8
 
9
+ validates_presence_of :country
10
+ validates_presence_of :name
5
11
 
12
+ def abbr
13
+ province.try(:abbr) || country.abbr
14
+ end
6
15
 
16
+ # Instantiate self.geom as a Point
17
+ def validation
18
+ self.country ||= province.country
19
+ unless !@x || !@y || @x == "" || @y == ""
20
+ self.geom = Point.from_x_y(@x.to_f, @y.to_f)
21
+ end
22
+ end
23
+
24
+ end
25
+ end
7
26
  end
@@ -0,0 +1,7 @@
1
+ module Geonames
2
+ module Mongo
3
+ class City < Geonames::Spot
4
+ set_coll "cities"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,61 @@
1
+ module Geonames
2
+ class Country
3
+ attr_accessor :code, :name, :gid, :iso, :capital, :pop
4
+
5
+ def self.all
6
+ Tokyo.new.all({ :kind => "country" }).map do |c|
7
+ new(c)
8
+ end
9
+ end
10
+
11
+ # [0] iso alpha2
12
+ # [1] iso alpha3
13
+ # [2] iso numeric
14
+ # [3] fips code
15
+ # [4] name
16
+ # [5] capital
17
+ # [6] areaInSqKm
18
+ # [7] population
19
+ # [8] continent
20
+ # [9] top level domain
21
+ # [10] Currency code
22
+ # [11] Currency name
23
+ # [12] Phone
24
+ # [13] Postal Code Format
25
+ # [14] Postal Code Regex
26
+ # [15] Languages
27
+ # [16] Geoname id
28
+ # [17] Neighbours
29
+ # [18] Equivalent Fips Code
30
+ #
31
+ def self.parse(row)
32
+ new(row)
33
+ end
34
+
35
+ def initialize(params)
36
+ parse(params)
37
+ end
38
+
39
+ def parse
40
+ @iso, @iso3, @ison, @fips, @name, @capital, @area, @pop, continent, tld,
41
+ currency, phone, postal, langs, gid, neighbours = row.split(/\t/)
42
+ @code = iso
43
+ end
44
+
45
+ def cities
46
+ # qry.addcond("country", TBDQRY::QSTREQ, @code)
47
+ end
48
+
49
+ def to_hash
50
+ { "gid" => @gid.to_s, "name" => @name, "kind" => "country", "code" => @code}
51
+ end
52
+
53
+ def export
54
+ [@gid, @code, @name]
55
+ end
56
+
57
+ def export_header
58
+ ["gid", "code", "name"]
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ module Geonames
2
+ class Province
3
+ attr_accessor :code, :name, :gid
4
+
5
+ def self.all
6
+ Tokyo.new.all({ :kind => "province" }).map do |c|
7
+ new(c)
8
+ end
9
+ end
10
+
11
+ def initialize(params)
12
+ @code = params["code"]
13
+ @name = params["name"]
14
+ @gid = params["gid"]
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_ar_helper')
3
+
4
+ class User < ActiveRecord::Base
5
+ belongs_to :city
6
+ end
7
+
8
+
9
+ describe "Active Record Stuff" do
10
+
11
+
12
+ it "should create" do
13
+ user = User.new(:name => "Defendor")
14
+ user.city = City.first
15
+ p City.first
16
+ user.save
17
+ User.first.city.name.should eql("Sao Tome")
18
+ end
19
+ end
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_ext_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_mongo_helper')
3
3
  require "geo_ruby"
4
+ include Geonames::Mongo
4
5
 
5
6
  describe City do
6
7
 
@@ -32,4 +33,8 @@ describe City do
32
33
  it "should find by name" do
33
34
  City.find_by_name("Rock")[0].name.should eql("Rock City")
34
35
  end
36
+
37
+ it "should find by name" do
38
+ City.find_by_name("rock")[0].name.should eql("Rock City")
39
+ end
35
40
  end
@@ -0,0 +1,55 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'spec'
4
+ require 'spec/autorun'
5
+ require 'active_record'
6
+ require 'postgis_adapter'
7
+ require 'geonames_ar'
8
+
9
+ ActiveRecord::Base.logger = $logger
10
+ ActiveRecord::Base.establish_connection({ :adapter => "postgresql",
11
+ :database => "geonames_ar",
12
+ :username => "postgres",
13
+ :password => "" })
14
+
15
+ ActiveRecord::Schema.define() do
16
+
17
+
18
+ create_table :users, :force => true do |t|
19
+ t.string :name, :nick, :limit => 100
20
+ t.string :email
21
+ t.integer :code
22
+ t.references :city
23
+ end
24
+ create_table :cities, :force => true do |t|
25
+ t.references :country, :null => false
26
+ t.references :province
27
+ t.string :name, :null => false
28
+ t.point :geom, :srid => 4326
29
+ t.integer :gid, :zip
30
+ end
31
+
32
+ create_table :provinces, :force => true do |t|
33
+ t.references :country, :null => false
34
+ t.string :name, :null => false
35
+ t.string :abbr, :limit => 2, :null => false
36
+ t.integer :gid
37
+ end
38
+
39
+ create_table :countries, :force => true do |t|
40
+ t.string :name, :limit => 30, :null => false
41
+ t.string :abbr, :limit => 2, :null => false
42
+ end
43
+
44
+ add_index :cities, :name
45
+ add_index :cities, :gid
46
+ add_index :cities, :zip
47
+ add_index :cities, :country_id
48
+ add_index :cities, :province_id
49
+ add_index :cities, :geom, :spatial => true
50
+ add_index :provinces, :name
51
+ add_index :provinces, :abbr
52
+ add_index :provinces, :gid
53
+ add_index :provinces, :country_id
54
+
55
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'geonames_local'
3
+ require 'geonames_cli'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
6
  include Geonames
@@ -1,5 +1,5 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'geonames_ext'
3
+ require 'geonames_local'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Marcos Piccinini
@@ -14,13 +14,14 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-20 00:00:00 -03:00
17
+ date: 2010-09-14 00:00:00 -03:00
18
18
  default_executable: geonames
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: nofxx-georuby
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
@@ -35,6 +36,7 @@ dependencies:
35
36
  name: rspec
36
37
  prerelease: false
37
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
38
40
  requirements:
39
41
  - - ">="
40
42
  - !ruby/object:Gem::Version
@@ -64,7 +66,8 @@ files:
64
66
  - bin/geonames
65
67
  - geonames.yml
66
68
  - geonames_local.gemspec
67
- - lib/geonames_ext.rb
69
+ - lib/geonames_ar.rb
70
+ - lib/geonames_cli.rb
68
71
  - lib/geonames_local.rb
69
72
  - lib/geonames_local/adapters/mongodb.rb
70
73
  - lib/geonames_local/adapters/postgres.rb
@@ -81,9 +84,11 @@ files:
81
84
  - lib/geonames_local/features/zone.rb
82
85
  - lib/geonames_local/geonames.rb
83
86
  - lib/geonames_local/model/city.rb
84
- - lib/geonames_local/model/conn.rb
85
87
  - lib/geonames_local/model/country.rb
86
88
  - lib/geonames_local/model/province.rb
89
+ - lib/geonames_local/mongo/city.rb
90
+ - lib/geonames_local/mongo/country.rb
91
+ - lib/geonames_local/mongo/province.rb
87
92
  - spec/geonames_local/adapters/mongodb_spec.rb
88
93
  - spec/geonames_local/adapters/postgres_spec.rb
89
94
  - spec/geonames_local/adapters/tokyo_spec.rb
@@ -93,46 +98,37 @@ files:
93
98
  - spec/geonames_local/features/road_spec.rb
94
99
  - spec/geonames_local/features/spot_spec.rb
95
100
  - spec/geonames_local/features/zone_spec.rb
96
- - spec/geonames_local/model/city_spec.rb
101
+ - spec/geonames_local/model/ar_spec.rb
102
+ - spec/geonames_local/mongo/city_spec.rb
97
103
  - spec/geonames_local_spec.rb
98
104
  - spec/spec.opts
99
- - spec/spec_ext_helper.rb
105
+ - spec/spec_ar_helper.rb
100
106
  - spec/spec_helper.rb
107
+ - spec/spec_mongo_helper.rb
101
108
  - task/benchmark.rb
102
109
  - task/benchmark_cabinet.rb
103
110
  has_rdoc: true
104
111
  homepage: http://github.com/nofxx/geonames_local
105
112
  licenses: []
106
113
 
107
- post_install_message: |
108
-
109
- Geonames Local
110
- --------------
111
-
112
- To use the adapter, install the corresponding gem:
113
-
114
- PostgreSQL => pg
115
- MongoDB => mongodb (optional: mongo_ext)
116
- Tokyo => tokyocabinet
117
-
118
- PostgreSQL
119
- ----------
120
-
121
- Be sure to use a database based on the PostGIS template.
122
-
123
- MongoDB
124
- -------
125
-
126
- MongoDB 2D support is new, only mongo >= 1.3.3 mongodb gem >= 0.19.2
127
- http://github.com/mongodb/mongo-ruby-driver
128
-
129
- Have fun because:
130
-
114
+ post_install_message: "\n\
115
+ Geonames Local\n\
116
+ --------------\n\n\
117
+ To use the adapter, install the corresponding gem:\n\n PostgreSQL => pg\n MongoDB => mongodb (optional: mongo_ext)\n Tokyo => tokyocabinet\n\n\
118
+ PostgreSQL\n\
119
+ ----------\n\n\
120
+ Be sure to use a database based on the PostGIS template.\n\n\
121
+ MongoDB\n\
122
+ -------\n\n\
123
+ MongoDB 2D support is new, only mongo >= 1.3.3 mongodb gem >= 0.19.2\n\
124
+ http://github.com/mongodb/mongo-ruby-driver\n\n\
125
+ Have fun because:\n"
131
126
  rdoc_options:
132
127
  - --charset=UTF-8
133
128
  require_paths:
134
129
  - lib
135
130
  required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
136
132
  requirements:
137
133
  - - ">="
138
134
  - !ruby/object:Gem::Version
@@ -140,6 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
136
  - 0
141
137
  version: "0"
142
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
143
140
  requirements:
144
141
  - - ">="
145
142
  - !ruby/object:Gem::Version
@@ -149,15 +146,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
146
  requirements: []
150
147
 
151
148
  rubyforge_project:
152
- rubygems_version: 1.3.6
149
+ rubygems_version: 1.3.7
153
150
  signing_key:
154
151
  specification_version: 3
155
152
  summary: Dump and feed a tokyo local geonames db
156
153
  test_files:
154
+ - spec/spec_ar_helper.rb
157
155
  - spec/spec_helper.rb
158
156
  - spec/geonames_local/data/shp_spec.rb
159
157
  - spec/geonames_local/data/cache_spec.rb
160
- - spec/geonames_local/model/city_spec.rb
158
+ - spec/geonames_local/model/ar_spec.rb
159
+ - spec/geonames_local/mongo/city_spec.rb
161
160
  - spec/geonames_local/cli_spec.rb
162
161
  - spec/geonames_local/adapters/postgres_spec.rb
163
162
  - spec/geonames_local/adapters/tokyo_spec.rb
@@ -165,5 +164,5 @@ test_files:
165
164
  - spec/geonames_local/features/spot_spec.rb
166
165
  - spec/geonames_local/features/zone_spec.rb
167
166
  - spec/geonames_local/features/road_spec.rb
167
+ - spec/spec_mongo_helper.rb
168
168
  - spec/geonames_local_spec.rb
169
- - spec/spec_ext_helper.rb
@@ -1,7 +0,0 @@
1
- require 'geonames_local/adapters/mongodb'
2
-
3
- module Geonames
4
-
5
- Adapter = Geonames::Mongodb.new
6
-
7
- end