geonames_dump 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -8
- data/lib/generators/geonames_dump/install_generator.rb +8 -1
- data/lib/generators/geonames_dump/templates/app/models/geonames_alternate_name.rb +11 -9
- data/lib/generators/geonames_dump/templates/app/models/geonames_feature.rb +3 -5
- data/lib/generators/geonames_dump/templates/db/migrate/create_geonames_features.rb +1 -1
- data/lib/geonames_dump/version.rb +1 -1
- data/lib/geonames_dump.rb +5 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51ed09afdea83aa1dc645d29853e3ebbb6df359d
|
4
|
+
data.tar.gz: 7a93c55528d389494eaecdf5bf3636fe5e920372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6d5480e18e38dce459baf68b3e05eb84bed0e0af2d96af3930aca5e3528913e5c09d99fc73c72e5ca7d6cb649f1986f8823ad4b61a9265d0855f52b3843fa4c
|
7
|
+
data.tar.gz: b23c2d146145bdeb3427e72c41a93fdc4bb7a6af88d7d56fc6bc2b6546e9c3b9684f1f25143b8a707770934fee84ce0f4afbcd54944844f61913a6c8089f9f8c
|
data/README.md
CHANGED
@@ -89,13 +89,13 @@ Search order is the following :
|
|
89
89
|
2. Alternate names (names in non-latin alphabets)
|
90
90
|
3. First level admin subdivisions
|
91
91
|
4. Second level admin subdivisions
|
92
|
-
5.
|
93
|
-
6. Features (lakes, montains and others various features)
|
92
|
+
5. Features (lakes, mountains and others various features)
|
94
93
|
|
95
94
|
Now to find a city for example :
|
96
95
|
|
97
96
|
```
|
98
97
|
GeonamesDump.search('paris')
|
98
|
+
GeonamesDump.search('東京') # tokyo :-)
|
99
99
|
```
|
100
100
|
|
101
101
|
If your request is ambiguous, like not searching Dublin in Ireland but Dublin
|
@@ -116,14 +116,22 @@ GeonamesDump.search('dublin, us', type: :city)
|
|
116
116
|
GeonamesDump.search('paris', type: :feature)
|
117
117
|
```
|
118
118
|
|
119
|
+
As `GeonamesDump.search` is returning `Feature` objects by default, type should
|
120
|
+
specified to search for Countries :
|
121
|
+
|
122
|
+
```
|
123
|
+
GeonamesDump.search('Ireland', type: :country)
|
124
|
+
```
|
125
|
+
|
119
126
|
The following types are available :
|
120
127
|
|
121
|
-
- admin1
|
122
|
-
- admin2
|
123
|
-
- city
|
124
|
-
- feature
|
125
|
-
-
|
126
|
-
-
|
128
|
+
- `:admin1`, for first level of adminstrative subdivision
|
129
|
+
- `:admin2`, for second level of adminstrative subdivision
|
130
|
+
- `:city`, for city names
|
131
|
+
- `:feature`, for generic names including all the above
|
132
|
+
- `:auto`, to find any type of feature (even with non-latin characters) matching the query
|
133
|
+
- `:alternate_name`, for names in non-latin alphabets (may be useless)
|
134
|
+
- `:country`, for country names
|
127
135
|
|
128
136
|
## Contributing
|
129
137
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'pry'
|
1
2
|
module GeonamesDump
|
2
3
|
module Generators
|
3
4
|
class InstallGenerator < Rails::Generators::Base
|
@@ -11,7 +12,13 @@ DESC
|
|
11
12
|
def copy_migrations_files
|
12
13
|
Dir.glob(File.join(File.expand_path(File.join('..', 'templates', 'db', 'migrate'), __FILE__), '*')).each do |full_path|
|
13
14
|
file = File.basename(full_path, File.extname(full_path))
|
14
|
-
|
15
|
+
migration_folder = File.join('db', 'migrate')
|
16
|
+
|
17
|
+
if self.class.migration_exists?(migration_folder, file)
|
18
|
+
say_status("skip", "Migration #{file} already exists", :yellow)
|
19
|
+
else
|
20
|
+
migration_template File.join(migration_folder, "#{file}.rb")
|
21
|
+
end
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
@@ -1,13 +1,15 @@
|
|
1
1
|
class GeonamesAlternateName < ActiveRecord::Base
|
2
2
|
validates_uniqueness_of :alternate_name_id
|
3
|
-
validates_uniqueness_of :geonameid
|
4
3
|
before_save :set_alternate_name_first_letters
|
5
4
|
|
5
|
+
belongs_to :geonames_feature, :foreign_key => 'geonameid', :inverse_of => :geonames_alternate_names, :primary_key => 'geonameid'
|
6
|
+
alias_method :feature, :geonames_feature
|
7
|
+
|
6
8
|
##
|
7
9
|
# default search (by alternate name)
|
8
10
|
#
|
9
11
|
scope :search, lambda { |q|
|
10
|
-
|
12
|
+
by_alternate_name_featured(q)
|
11
13
|
}
|
12
14
|
|
13
15
|
##
|
@@ -24,6 +26,13 @@ class GeonamesAlternateName < ActiveRecord::Base
|
|
24
26
|
where(is_preferred_name: true)
|
25
27
|
}
|
26
28
|
|
29
|
+
##
|
30
|
+
# search by name for available features
|
31
|
+
#
|
32
|
+
scope :by_alternate_name_featured, lambda { |q|
|
33
|
+
joins(:geonames_feature).by_alternate_name(q).where(GeonamesFeature.arel_table[:id].not_eq(nil))
|
34
|
+
}
|
35
|
+
|
27
36
|
##
|
28
37
|
# search by name
|
29
38
|
#
|
@@ -33,13 +42,6 @@ class GeonamesAlternateName < ActiveRecord::Base
|
|
33
42
|
ret = ret.where("alternate_name LIKE ?", "#{q}%")
|
34
43
|
}
|
35
44
|
|
36
|
-
##
|
37
|
-
# Get associated feature
|
38
|
-
#
|
39
|
-
def feature
|
40
|
-
GeonamesFeature.where(geonameid: self.geonameid)
|
41
|
-
end
|
42
|
-
|
43
45
|
protected
|
44
46
|
|
45
47
|
##
|
@@ -2,6 +2,9 @@ class GeonamesFeature < ActiveRecord::Base
|
|
2
2
|
validates_uniqueness_of :geonameid
|
3
3
|
before_save :set_asciiname_first_letters
|
4
4
|
|
5
|
+
has_many :geonames_alternate_names, :inverse_of => :geonames_feature
|
6
|
+
alias_method :alternate_names, :geonames_alternate_names
|
7
|
+
|
5
8
|
##
|
6
9
|
# Search for feature, searches might include country (separated by ',')
|
7
10
|
#
|
@@ -39,11 +42,6 @@ class GeonamesFeature < ActiveRecord::Base
|
|
39
42
|
ret
|
40
43
|
}
|
41
44
|
|
42
|
-
def alternate_names
|
43
|
-
GeonamesAlternateName.where(geonameid: self.geonameid)
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
45
|
protected
|
48
46
|
|
49
47
|
##
|
@@ -24,7 +24,7 @@ class CreateGeonamesFeatures < ActiveRecord::Migration
|
|
24
24
|
t.integer :geonameid
|
25
25
|
t.string :name, length: 200
|
26
26
|
t.string :asciiname, length: 200
|
27
|
-
t.
|
27
|
+
t.text :alternatenames, length: 5000
|
28
28
|
t.float :latitude
|
29
29
|
t.float :longitude
|
30
30
|
t.string :feature_class
|
data/lib/geonames_dump.rb
CHANGED
@@ -3,37 +3,32 @@ require "geonames_dump/blocks"
|
|
3
3
|
require "geonames_dump/railtie" #if defined?(Rails)
|
4
4
|
|
5
5
|
module GeonamesDump
|
6
|
-
# TODO: remove this logger
|
7
|
-
#ActiveRecord::Base.logger = Logger.new(STDOUT) if Rails.env.development? && !ENV['SILENT']
|
8
|
-
|
9
6
|
def self.search(query, options = {})
|
10
7
|
ret = nil
|
11
8
|
|
12
9
|
type = options[:type] || :auto
|
13
10
|
begin
|
14
11
|
case type
|
15
|
-
when :auto
|
12
|
+
when :auto # return an array of features
|
16
13
|
# city name
|
17
14
|
ret = GeonamesCity.search(query)
|
18
15
|
# alternate name
|
19
|
-
ret = GeonamesAlternateName.search(query) if ret.blank?
|
16
|
+
ret = GeonamesAlternateName.search(query).map { |alternate| alternate.feature }.compact if ret.blank?
|
20
17
|
# admin1
|
21
18
|
ret = GeonamesAdmin1.search(query) if ret.blank?
|
22
19
|
# admin2
|
23
20
|
ret = GeonamesAdmin2.search(query) if ret.blank?
|
24
|
-
# country
|
25
|
-
ret = GeonamesCountry.search(query) if ret.blank?
|
26
21
|
# feature
|
27
22
|
ret = GeonamesFeature.search(query) if ret.blank?
|
28
|
-
else
|
23
|
+
else # country, or specific type
|
29
24
|
model = "geonames_#{type.to_s}".camelcase.constantize
|
30
25
|
ret = model.search(query)
|
31
26
|
end
|
32
27
|
rescue NameError => e
|
33
|
-
|
34
|
-
#raise
|
28
|
+
raise $!, "Unknown type for GeonamesDump, #{$!}", $!.backtrace
|
35
29
|
end
|
36
30
|
|
31
|
+
|
37
32
|
ret
|
38
33
|
end
|
39
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geonames_dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Pooley
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-progressbar
|