city_search 0.0.1 → 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.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/city_search.gemspec +2 -2
- data/data/{dawg.bin → all.bin} +0 -0
- data/data/{state-countries.bin → all_states.bin} +0 -0
- data/data/russia.bin +0 -0
- data/data/russia_states.bin +0 -0
- data/lib/city_search.rb +18 -9
- metadata +8 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b80b8084db7d36585b0b89383d7536a7726522dbad08a9ee3874c2dcac6bfa32
|
|
4
|
+
data.tar.gz: cfe894eeadc1ce0aea59fc2811c9ca49e0edf66221d0f62e69abd5386e2bd335
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a7d4c9274bce0ae8f097763e5c73d145a24ff5539da62c71cdda9008edcbc5f3fc8f57053964c52c1a84669420fcf40735aa0ffb2864b6cec79a0e1401b45b1e
|
|
7
|
+
data.tar.gz: c6d71984278c657663659c4bcb14e1b6a0b741a6d865caa5b5366616372731d68efe90d36a9610d38d8c727071e8f11b0cc6d4572a42c9feb424d3be7f60703f
|
data/.gitignore
ADDED
data/city_search.gemspec
CHANGED
data/data/{dawg.bin → all.bin}
RENAMED
|
File without changes
|
|
File without changes
|
data/data/russia.bin
ADDED
|
Binary file
|
|
Binary file
|
data/lib/city_search.rb
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
require 'dawg'
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
class CitySearch
|
|
4
|
+
def initialize(country = :all)
|
|
5
|
+
raise 'country not found' unless country_exists?(country)
|
|
6
|
+
|
|
7
|
+
@country = country
|
|
8
|
+
end
|
|
9
|
+
|
|
4
10
|
def search(q)
|
|
5
|
-
results =
|
|
11
|
+
results = db.query(q).reject {|r| r.empty? }
|
|
6
12
|
results.map do |r|
|
|
7
13
|
result = r.split(' ')
|
|
8
14
|
code = result.last
|
|
9
15
|
result.pop
|
|
10
|
-
result
|
|
16
|
+
result += states[code.to_i]
|
|
11
17
|
end
|
|
12
18
|
end
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
def country_exists?(country)
|
|
21
|
+
File.exists?(File.dirname(__FILE__) + "/../data/#{country}.bin")
|
|
22
|
+
end
|
|
15
23
|
|
|
16
|
-
def
|
|
17
|
-
|
|
24
|
+
def db
|
|
25
|
+
@all ||= Dawg.load(File.dirname(__FILE__) + "/../data/#{@country}.bin")
|
|
18
26
|
end
|
|
19
27
|
|
|
20
28
|
def states
|
|
21
|
-
|
|
29
|
+
@states ||= Marshal.load(
|
|
30
|
+
File.read(File.dirname(__FILE__) + "/../data/#{@country}_states.bin")
|
|
31
|
+
)
|
|
22
32
|
end
|
|
23
|
-
|
|
24
33
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: city_search
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maksatbek Mansurov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: dawg
|
|
@@ -36,9 +36,12 @@ executables: []
|
|
|
36
36
|
extensions: []
|
|
37
37
|
extra_rdoc_files: []
|
|
38
38
|
files:
|
|
39
|
+
- ".gitignore"
|
|
39
40
|
- city_search.gemspec
|
|
40
|
-
- data/
|
|
41
|
-
- data/
|
|
41
|
+
- data/all.bin
|
|
42
|
+
- data/all_states.bin
|
|
43
|
+
- data/russia.bin
|
|
44
|
+
- data/russia_states.bin
|
|
42
45
|
- lib/city_search.rb
|
|
43
46
|
homepage: http://rubygems.org/gems/city_search
|
|
44
47
|
licenses:
|
|
@@ -60,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
60
63
|
version: '0'
|
|
61
64
|
requirements: []
|
|
62
65
|
rubyforge_project:
|
|
63
|
-
rubygems_version: 2.
|
|
66
|
+
rubygems_version: 2.7.6
|
|
64
67
|
signing_key:
|
|
65
68
|
specification_version: 4
|
|
66
69
|
summary: City Search
|