geonames_local 3.3.1 → 3.3.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c788cde1271fbcde5596ca18134547b68ebe2488
4
- data.tar.gz: 983752fea10114e374c21e75e23b5e21808c31fe
3
+ metadata.gz: 3d899c1e90546accbce85fa372b534d862f81d16
4
+ data.tar.gz: b0978645a9ae924f268bb8783a82e2de3564a733
5
5
  SHA512:
6
- metadata.gz: a7a08a957601e2663126bd6fe7c5021b46b6527e0e15a1549e8b6971b5ad688443f82c73aad92ba44e93f4e48567a6034a108c742c24d92bb472af2fb92ee369
7
- data.tar.gz: eb7b597058aa178b5e8f28f1d565a9b586dd7099d3b6675b3d32bc99ca45c1fc13d2b7f3020b532d5e12a7ae0af69f71af223e95cbb10b1ba13413a161f31204
6
+ metadata.gz: d907b4d932d092bae9b440b31226e12d8c68d8b54e5806076dde56c7b68569f5087352903d97db250d7dc603f14418499527758823a6428f20485d8cc2bee8ab
7
+ data.tar.gz: fa3189ca4d1c1ae453dcd1c7e6cd8d9fc227fd2524fbff07f87e6584e1858295a5b72ec40812b27e1353c448113af571466cc581fd82647ab34ccfccd2597489
data/Gemfile CHANGED
@@ -1,15 +1,18 @@
1
1
  source 'http://rubygems.org'
2
2
  gemspec # Specify gem's dependencies in mongoid_geospatial.gemspec
3
3
 
4
- group :development do
5
- gem 'mongoid'
6
- gem 'mongoid_geospatial'
7
- # gem 'pg'
4
+ gem 'rake'
5
+ gem 'dbf'
6
+
7
+ platforms :ruby do
8
8
  gem 'rgeo'
9
- gem 'georuby'
10
- gem 'dbf'
11
- gem 'rspec'
12
- gem 'guard-rspec'
13
- gem 'pry'
14
- # gem 'fuubar'
15
9
  end
10
+
11
+ gem 'georuby'
12
+
13
+ gem 'mongoid'
14
+ gem 'mongoid_geospatial'
15
+
16
+ gem 'pry'
17
+ gem 'rspec'
18
+ gem 'guard-rspec'
data/Guardfile CHANGED
@@ -4,6 +4,6 @@ require 'guard'
4
4
 
5
5
  guard 'rspec' do
6
6
  watch(%r{^spec/.+_spec\.rb$})
7
- watch(%r{^lib/(.+)\.rb$}) { "spec" } # { |m| "spec spec/lib/#{m[1]}_spec.rb" }
8
- watch('spec/spec_helper.rb') { "spec" }
7
+ watch(%r{^lib/(.+)\.rb$}) { 'spec' } # { |m| "spec spec/lib/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { 'spec' }
9
9
  end
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
3
3
 
4
4
  require 'rspec/core'
5
5
  require 'rspec/core/rake_task'
@@ -13,49 +13,48 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
13
13
  spec.rcov = true
14
14
  end
15
15
 
16
- task :default => :spec
16
+ task default: :spec
17
17
 
18
18
  require 'yard'
19
19
 
20
-
21
20
  #
22
21
  # Tokyo Tyrant rake tasks
23
22
  #
24
23
  namespace :tyrant do
25
- TYRANT_DB_FILE = File.join("tyrant.tct")
26
- TYRANT_PID_FILE = File.join("tyrant.pid")
27
- TYRANT_LOG_FILE = File.join("tyrant.log")
24
+ TYRANT_DB_FILE = File.join('tyrant.tct')
25
+ TYRANT_PID_FILE = File.join('tyrant.pid')
26
+ TYRANT_LOG_FILE = File.join('tyrant.log')
28
27
 
29
- desc "Start Tyrant server"
28
+ desc 'Start Tyrant server'
30
29
  task :start do
31
- raise RuntimeError, "Tyrant is already running." if tyrant_running?
30
+ fail RuntimeError, 'Tyrant is already running.' if tyrant_running?
32
31
  system "ttserver -pid #{TYRANT_PID_FILE} -log #{TYRANT_LOG_FILE} #{TYRANT_DB_FILE}&"
33
32
  sleep(2)
34
33
  if tyrant_running?
35
34
  puts "Tyrant started successfully (pid #{tyrant_pid})."
36
35
  else
37
- puts "Failed to start tyrant push server. Check logs."
36
+ puts 'Failed to start tyrant push server. Check logs.'
38
37
  end
39
38
  end
40
39
 
41
- desc "Stop Tyrant server"
40
+ desc 'Stop Tyrant server'
42
41
  task :stop do
43
- raise RuntimeError, "Tyrant isn't running." unless tyrant_running?
42
+ fail RuntimeError, "Tyrant isn't running." unless tyrant_running?
44
43
  system "kill #{tyrant_pid}"
45
44
  sleep(2)
46
45
  if tyrant_running?
47
46
  puts "Tyrant didn't stopped. Check the logs."
48
47
  else
49
- puts "Tyrant stopped."
48
+ puts 'Tyrant stopped.'
50
49
  end
51
50
  end
52
51
 
53
- desc "Restart Tyrant server"
54
- task :restart => [:stop, :start]
52
+ desc 'Restart Tyrant server'
53
+ task restart: [:stop, :start]
55
54
 
56
- desc "Get Tyrant Server Status"
55
+ desc 'Get Tyrant Server Status'
57
56
  task :status do
58
- puts tyrant_running? ? "Tyrant running. (#{tyrant_pid})" : "Tyrant not running."
57
+ puts tyrant_running? ? "Tyrant running. (#{tyrant_pid})" : 'Tyrant not running.'
59
58
  end
60
59
  end
61
60
 
@@ -67,7 +66,7 @@ def tyrant_running?
67
66
  return false unless File.exist?(TYRANT_PID_FILE)
68
67
  process_check = `ps -p #{tyrant_pid} | wc -l`
69
68
  if process_check.to_i < 2
70
- puts "Erasing pidfile..."
69
+ puts 'Erasing pidfile...'
71
70
  `rm #{TYRANT_PID_FILE}`
72
71
  end
73
72
  tyrant_pid
data/geonames.yml CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  :store: mongodb
5
5
  :level: city
6
- :nations: [br]
6
+ :nations: [br, it, nl]
7
7
  :locales: [pt, en]
8
8
  :min_pop: 100000
9
9
  :mapping:
@@ -11,7 +11,7 @@
11
11
  :geom: true
12
12
  :db:
13
13
  :host: localhost
14
- :name: baccafe_development
14
+ :name: geonames_test
15
15
  :user:
16
16
  :pass:
17
17
  :purge: false
@@ -2,33 +2,32 @@
2
2
  require File.expand_path('../lib/geonames_local/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.name = %q{geonames_local}
5
+ gem.name = 'geonames_local'
6
6
  gem.version = Geonames::VERSION
7
- gem.homepage = %q{http://github.com/nofxx/geonames_local}
7
+ gem.homepage = 'http://github.com/nofxx/geonames_local'
8
8
 
9
- gem.authors = ["Marcos Piccinini"]
10
- gem.default_executable = %q{geonames}
11
- gem.description = %q{Dumps geonames data to feed a local db}
12
- gem.email = %q{x@nofxx.com}
13
- gem.license = "MIT"
9
+ gem.authors = ['Marcos Piccinini']
10
+ gem.default_executable = 'geonames'
11
+ gem.description = 'Dumps geonames data to feed a local db'
12
+ gem.email = 'x@nofxx.com'
13
+ gem.license = 'MIT'
14
14
 
15
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
16
16
  gem.files = `git ls-files`.split("\n")
17
17
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- gem.name = "geonames_local"
19
- gem.require_paths = ["lib"]
20
- gem.summary = %q{Dumps geonames data for local usage}
21
-
18
+ gem.name = 'geonames_local'
19
+ gem.require_paths = ['lib']
20
+ gem.summary = 'Dumps geonames data for local usage'
22
21
 
23
22
  gem.extra_rdoc_files = [
24
- "MIT-LICENSE",
25
- "README.md"
23
+ 'MIT-LICENSE',
24
+ 'README.md'
26
25
  ]
27
26
 
28
- gem.add_dependency('mongoid', ['~> 3.1.0'])
27
+ gem.add_dependency('mongoid', ['> 3.0.0'])
29
28
  gem.add_dependency('geopolitical', ['> 0.8.1'])
30
29
 
31
- gem.post_install_message = %q{
30
+ gem.post_install_message = '
32
31
  Geonames Local
33
32
  --------------
34
33
 
@@ -36,5 +35,6 @@ Use `geonames init` to create a config.yml file.
36
35
  Or `geonames -c config.yml` to run using a config file.
37
36
 
38
37
  Have fun!
39
- }
38
+
39
+ '
40
40
  end
@@ -2,13 +2,11 @@
2
2
  # Geonames Local
3
3
  #
4
4
  require 'optparse'
5
+ require 'benchmark'
5
6
  # Require CLI Stuff
6
- require 'geonames_local/geonames'
7
7
  require 'geonames_local/data/shp'
8
8
  require 'geonames_local/data/dump'
9
9
  require 'geonames_local/data/export'
10
- require 'geonames_local/cli'
11
-
12
10
 
13
11
  module Geonames
14
12
  #
@@ -23,7 +21,7 @@ module Geonames
23
21
  opts.banner = 'Geonames Command Line Usage\n\n geonames <nation code(s)> <opts>\n\n\n'
24
22
 
25
23
  opts.on('-l', '--level LEVEL', String, 'The level of logging to report') { |level| options[:level] = level }
26
- opts.on('-d', '--dump', 'Dump DB before all') { options[:dump] = true }
24
+ opts.on('-d', '--dump', 'Dump DB before all') { options[:clean] = true }
27
25
  opts.separator ''
28
26
  opts.separator 'Config file:'
29
27
  opts.on('-c', '--config CONFIG', String, 'Geonames Config file path') { |file| options[:config] = file }
@@ -57,14 +55,13 @@ module Geonames
57
55
  private_class_method :parse_options
58
56
 
59
57
  class << self
60
-
61
58
  def load_config
62
- info "Loading config file..."
59
+ info 'Loading config file...'
63
60
  if Opt[:config]
64
61
  Opt.merge! YAML.load(File.read(Opt[:config]))
65
62
  else
66
63
  # Load config/geonames.yml if there's one
67
- if File.exists?(cfg = File.join('config', 'geonames.yml'))
64
+ if File.exist?(cfg = File.join('config', 'geonames.yml'))
68
65
  Opt.merge! YAML.load(File.read(cfg))
69
66
  else
70
67
  fail
@@ -75,12 +72,42 @@ module Geonames
75
72
  exit
76
73
  end
77
74
 
78
- # Ugly but works?
79
- def work(argv)
80
- info "Geopolitical Local Start!"
81
-
75
+ def trap_signals
76
+ puts 'Geopolitical Local Start!'
82
77
  trap(:INT) { stop! }
83
78
  trap(:TERM) { stop! }
79
+ end
80
+
81
+ def wrapper
82
+ Geonames::Models::MongoWrapper
83
+ end
84
+
85
+ def work_nations
86
+ info "\nPopulating 'nations' database..."
87
+ dump = Geonames::Dump.new(:all, :dump)
88
+ info "\n---\nTotal #{dump.data.length} parsed."
89
+
90
+ info 'Writing to nations DB'
91
+ wrapper.nations dump.data
92
+ end
93
+
94
+ def work_spots
95
+ info "\nPopulating 'regions' and 'cities' database..."
96
+ zip = Geonames::Dump.new(Opt[:nations], :zip).data
97
+ dump = Geonames::Dump.new(Opt[:nations], :dump).data
98
+ info "\n---\nTotal #{dump.size} parsed. #{zip.size} zip codes."
99
+
100
+ info 'Join dump << zip'
101
+ dump = unify!(dump, zip).group_by(&:kind)
102
+
103
+ info 'Writing to DB...'
104
+ wrapper.batch dump
105
+ end
106
+
107
+ # Ugly but works?
108
+ def work(argv)
109
+ start = Time.now
110
+ trap_signals
84
111
  Opt.merge! parse_options(argv)
85
112
  if Opt[:locales].nil? || Opt[:locales].empty?
86
113
  Opt[:locales] = ['en']
@@ -95,7 +122,7 @@ module Geonames
95
122
  # Return Codes and Exit
96
123
  #
97
124
  if argv[0] =~ /list|codes/
98
- Codes.each do |key,val|
125
+ Codes.each do |key, val|
99
126
  str = [val.values, key.to_s].join(' ').downcase
100
127
  if s = argv[1]
101
128
  next unless str =~ /#{s.downcase}/
@@ -119,85 +146,42 @@ module Geonames
119
146
  exit
120
147
  end
121
148
 
122
- #
123
- # Require georuby optionally
124
- #
125
- require 'geo_ruby' if Opt[:mapping] && Opt[:mapping][:geom]
126
-
127
- #
128
149
  # Load config if we got til here
129
- #
130
150
  load_config
131
151
 
132
- #
133
152
  # Export Data as CSV or JSON
134
- #
135
- if argv[0] =~ /csv|json/
136
- Geonames::Export.new(Nation.all).to_csv
137
-
138
- #
139
- # Do the magic! Import Geonames Data
140
- #
141
- else
142
- load_adapter(Opt[:store])
143
- info "Using adapter #{Opt[:store]}.."
144
-
145
- # Nations
146
- if Opt[:nations].empty? || argv[0] =~ /coun|nati/
147
- info "\nPopulating 'nations' database..."
148
- dump = Geonames::Dump.new(:all, :dump)
149
- info "\n---\nTotal #{dump.data.length} parsed."
150
-
151
- info 'Writing to nations DB'
152
- Geonames::Models::MongoWrapper.nations dump.data, Opt[:clean]
153
-
154
- # Regions, Cities....
155
- else
156
- zip = Geonames::Dump.new(Opt[:nations], :zip).data
157
- dump = Geonames::Dump.new(Opt[:nations], :dump).data
158
- info "\n---\nTotal #{dump.size} parsed. #{zip.size} zips."
159
-
160
- info 'Join dump << zip'
161
- dump = unify!(dump, zip).group_by(&:kind)
162
-
163
- info 'Writing to DB...'
164
- Geonames::Models::MongoWrapper.batch dump, Opt[:clean]
165
- # info "Writing cities..."
166
- # Geonames::Models::City.from_batch dump[:city]
167
- end
168
- end
153
+ return Geonames::Export.new(Nation.all).to_csv if argv[0] =~ /csv|json/
154
+
155
+ # Do the magic! Import Geonames Data
156
+ load_adapter(Opt[:store])
157
+ info "Using adapter #{Opt[:store]}.."
158
+ wrapper.clean if Opt[:clean]
159
+ Benchmark.measure { work_nations } unless wrapper.nations_populated?
160
+ Benchmark.measure { work_spots }
169
161
  end
170
162
 
171
163
  def load_adapter(name)
172
- begin
173
- require "geonames_local/models/#{name}"
174
- rescue LoadError
175
- info "Can't find adapter for #{name}"
176
- stop!
177
- end
164
+ require_relative "models/#{name}"
165
+ rescue LoadError => e
166
+ info "Can't find adapter for #{name} #{e}"
167
+ stop!
178
168
  end
179
169
 
180
170
  def unify!(dump, zip)
181
171
  start = Time.now
182
172
  dump.map! do |spot|
183
- if other = zip.find { |d| d.code == spot.code }
184
- spot.zip = other.zip
185
- spot
186
- else
187
- spot
188
- end
173
+ next spot unless (other = zip.find { |z| z.code == spot.code })
174
+ spot.zip = other.zip
175
+ spot
189
176
  end
190
177
  info "Done. #{(Time.now - start).to_i}s"
191
178
  dump
192
179
  end
193
180
 
194
181
  def stop!
195
- puts 'Closing Geonames...'
182
+ info 'Closing Geonames...'
196
183
  exit
197
184
  end
198
-
199
185
  end # class < self
200
-
201
186
  end # CLI
202
-
203
187
  end # Geonames
@@ -1,18 +1,18 @@
1
1
  module Geonames
2
2
  class Dump
3
+ attr_reader :data
4
+
3
5
  # Geonames base URL
4
- URL = "http://download.geonames.org/export/"
6
+ URL = 'http://download.geonames.org/export/'
5
7
  # Work temporary files
6
- TMP = "/tmp/geonames/"
8
+ TMP = '/tmp/geonames/'
7
9
 
8
10
  def initialize(target, kind)
9
11
  @kind = kind
10
12
  @data = []
11
- if target.respond_to? :each
12
- target.each { |n| work(n) }
13
- elsif target == :all
14
- nations
15
- end
13
+
14
+ target.each { |n| work(n) } if target.respond_to? :each
15
+ nations if target == :all
16
16
  end
17
17
 
18
18
  def nations
@@ -22,7 +22,7 @@ module Geonames
22
22
  parse file
23
23
  end
24
24
 
25
- def work nation
25
+ def work(nation)
26
26
  info "\nWorking on #{@kind} for #{nation}"
27
27
  file = get_file(nation)
28
28
  download file
@@ -30,19 +30,15 @@ module Geonames
30
30
  parse file
31
31
  end
32
32
 
33
- def data
34
- @data
35
- end
36
-
37
33
  def get_file(nation)
38
- nation == "nation" ? "countryInfo.txt" : "#{nation.upcase}.zip"
34
+ nation == 'nation' ? 'countryInfo.txt' : "#{nation.upcase}.zip"
39
35
  end
40
36
 
41
37
  def download(file)
42
- Dir.mkdir(TMP) unless File.exists?(TMP)
43
- Dir.mkdir(TMP + @kind.to_s) unless File.exists?(TMP + @kind.to_s)
38
+ Dir.mkdir(TMP) unless File.exist?(TMP)
39
+ Dir.mkdir(TMP + @kind.to_s) unless File.exist?(TMP + @kind.to_s)
44
40
  fname = TMP + "#{@kind}/#{file}"
45
- return if File.exists?(fname)
41
+ return if File.exist?(fname)
46
42
  `curl #{URL}/#{@kind}/#{file} -o #{fname}`
47
43
  end
48
44
 
@@ -54,34 +50,27 @@ module Geonames
54
50
  def parse_line(l)
55
51
  return if l =~ /^#|^iso/i
56
52
  if @kind == :dump
57
- if l =~ /^\D/
58
- return l
59
- else
60
- if Opt[:level] != "all"
61
- return unless l =~ /ADM\d/ # ADM2 => cities
62
- end
53
+ return l if l =~ /^\D/
54
+ if Opt[:level] != 'all'
55
+ return unless l =~ /ADM\d/ # ADM2 => cities
63
56
  end
64
57
  end
65
58
  Spot.new(l, @kind)
66
59
  end
67
60
 
68
61
  def parse(file)
69
- red = 0
70
62
  start = Time.now
71
- File.open("/tmp/geonames/#{@kind}/#{file.gsub("zip", "txt")}") do |f|
63
+ File.open("/tmp/geonames/#{@kind}/#{file.gsub('zip', 'txt')}") do |f|
72
64
  while line = f.gets
73
65
  if record = parse_line(line)
74
66
  @data << record
75
- red += 1
76
67
  end
77
68
  end
78
69
  total = Time.now - start
79
- info "#{red} #{@kind} spots parsed #{total}s (#{(red / total).to_i}/s)"
70
+ info "#{@data.size} #{@kind} spots parsed #{total}s (#{(@data.size / total).to_i}/s)"
80
71
  end
81
- rescue Errno::ENOENT => e
72
+ rescue Errno::ENOENT => e
82
73
  info "Failed to download #{file}, skipping. #{e}"
83
74
  end
84
-
85
75
  end
86
-
87
76
  end
@@ -2,20 +2,19 @@ require 'csv'
2
2
 
3
3
  module Geonames
4
4
  class Export
5
-
6
5
  def initialize(data)
7
- info "Starting export.."
6
+ info 'Starting export..'
8
7
  @data = data
9
8
  end
10
9
 
11
10
  def to_csv
12
- file = "export.csv"
11
+ file = 'export.csv'
13
12
  info "Writing #{file} (#{@data.length} objects)"
14
- CSV.open("export.csv", 'w') do |csv|
13
+ CSV.open('export.csv', 'w') do |csv|
15
14
  csv << @data[0].export_header
16
15
  @data.each { |o| csv << o.export }
17
16
  end
18
- info "Export done."
17
+ info 'Export done.'
19
18
  end
20
19
  end
21
20
  end
@@ -4,10 +4,9 @@
4
4
 
5
5
  module Geonames
6
6
  class SHP
7
-
8
7
  def initialize(file)
9
8
  @file = file
10
- @fname = file.split("/")[-1] rescue nil
9
+ @fname = file.split('/')[-1] rescue nil
11
10
  @type = Object.module_eval("::#{Opt[:type].capitalize}", __FILE__, __LINE__)
12
11
  # @ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
13
12
  @sample = nil
@@ -17,7 +16,7 @@ module Geonames
17
16
  end
18
17
 
19
18
  def shp2pg
20
- info "Converting SRID"
19
+ info 'Converting SRID'
21
20
  `shp2pgsql -D -as 4326 #{@file} nil > /tmp/#{@fname}.dump`
22
21
  end
23
22
 
@@ -32,7 +31,7 @@ module Geonames
32
31
  end
33
32
 
34
33
  def parse
35
- info "Parsing dump"
34
+ info 'Parsing dump'
36
35
  start = Time.now
37
36
  red = 0
38
37
  File.open("/tmp/#{@fname}.dump") do |f|
@@ -44,15 +43,15 @@ module Geonames
44
43
  end
45
44
  end
46
45
  end
47
- info "#{red} parsed. #{Time.now-start}s"
46
+ info "#{red} parsed. #{Time.now - start}s"
48
47
  end
49
48
 
50
49
  def reduce!
51
- hsh = Cache[:roads].group_by { |r| r.name }
50
+ hsh = Cache[:roads].group_by(&:name)
52
51
  arr = []
53
- hsh.map do |key, vals|
52
+ hsh.map do |_key, vals|
54
53
  first = vals.delete_at(0)
55
- # p vals[0].geom.geometries.concat(vals[1].geom.geometries)
54
+ # p vals[0].geom.geometries.concat(vals[1].geom.geometries)
56
55
  vals.map(&:geom).each do |g|
57
56
  first.geom.geometries.concat g.geometries
58
57
  end
@@ -1,10 +1,10 @@
1
- require "rubygems"
2
- require "geo_ruby"
3
-
1
+ #
2
+ # Road/Street/Via/Autoban
3
+ #
4
4
  class Road
5
5
  attr_reader :city, :region, :nation, :zone, :name, :geom, :kind, :table
6
6
 
7
- def initialize(keys, vals, nation=nil, city=nil)
7
+ def initialize(keys, vals, nation = nil, city = nil)
8
8
  s = vals.split("\t")
9
9
  r = {}
10
10
  keys.each_with_index do |k, i|
@@ -12,7 +12,7 @@ class Road
12
12
  end
13
13
  @name = r[:name]
14
14
  @zone = r[:zone]
15
- kind = r[:kind] || @name.split(" ")[0]
15
+ kind = r[:kind] || @name.split(' ')[0]
16
16
  @geom = parse_geom(r[:geom])
17
17
  @kind = parse_kind(kind)
18
18
  @city = city
@@ -22,14 +22,12 @@ class Road
22
22
 
23
23
  def parse_geom(hex)
24
24
  if hex =~ /^SRID/ # PG 8.3 support
25
- hex = hex.split(";")[1]
25
+ hex = hex.split(';')[1]
26
26
  end
27
27
  GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(hex)
28
28
  end
29
29
 
30
- def geom=(g)
31
- @geom = g
32
- end
30
+ attr_writer :geom
33
31
 
34
32
  def parse_kind(k)
35
33
  case k
@@ -40,5 +38,4 @@ class Road
40
38
  else :unknown
41
39
  end
42
40
  end
43
-
44
41
  end
@@ -5,10 +5,10 @@ module Geonames
5
5
  class Spot
6
6
  attr_accessor :gid, :name, :ascii, :lat, :lon, :nation, :kind,
7
7
  :code, :pop, :tz, :geom, :region, :zip, :abbr, :id
8
- alias :x :lon
9
- alias :y :lat
10
- alias :geoname_id :gid
11
- alias :table :kind
8
+ alias_method :x, :lon
9
+ alias_method :y, :lat
10
+ alias_method :geoname_id, :gid
11
+ alias_method :table, :kind
12
12
 
13
13
  #
14
14
  # = Geonames Spot
@@ -97,7 +97,6 @@ module Geonames
97
97
  end
98
98
 
99
99
  class << self
100
-
101
100
  attr_accessor :collection
102
101
 
103
102
  def nearest(x, y)
@@ -110,9 +109,6 @@ module Geonames
110
109
  spot.geom = GeoRuby::SimpleFeatures::Point.from_x_y(*spot.geom)
111
110
  spot
112
111
  end
113
-
114
112
  end
115
-
116
113
  end
117
-
118
114
  end
@@ -1,10 +1,10 @@
1
- require "rubygems"
2
- require "geo_ruby"
3
-
1
+ #
2
+ # A polygon basically.
3
+ #
4
4
  class Zone
5
5
  attr_reader :city, :name, :geom, :kind
6
6
 
7
- def initialize(keys, vals, city=nil)
7
+ def initialize(keys, vals, city = nil)
8
8
  s = vals.split("\t")
9
9
  r = {}
10
10
  keys.each_with_index do |k, i|
@@ -20,5 +20,4 @@ class Zone
20
20
  def parse_geom(hex)
21
21
  @geom = GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(hex)
22
22
  end
23
-
24
23
  end