city_search 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2f803d9046a66a99e13fbe8a14dd14b10b3b1bf3
4
- data.tar.gz: 91cf04bfec8449b83aedd8680961521c0431ad6e
2
+ SHA256:
3
+ metadata.gz: b80b8084db7d36585b0b89383d7536a7726522dbad08a9ee3874c2dcac6bfa32
4
+ data.tar.gz: cfe894eeadc1ce0aea59fc2811c9ca49e0edf66221d0f62e69abd5386e2bd335
5
5
  SHA512:
6
- metadata.gz: 4e5a3d0fc882440bf5588dad4b2c38fa8ec285f56963c410a4c9166c0fcc1f5cd7d320b65396a2f80cfacbcd4a3fdf7e7fef5dfa637e20c46d5ecc290d613fe6
7
- data.tar.gz: e185302fb178ff2d60b8d1333426c460a74fbffa2b64c4d41c3150156c6de789a0c52ea6716df0816709331035fde846119f305b080ce06b75c64df3d7b5734f
6
+ metadata.gz: a7d4c9274bce0ae8f097763e5c73d145a24ff5539da62c71cdda9008edcbc5f3fc8f57053964c52c1a84669420fcf40735aa0ffb2864b6cec79a0e1401b45b1e
7
+ data.tar.gz: c6d71984278c657663659c4bcb14e1b6a0b741a6d865caa5b5366616372731d68efe90d36a9610d38d8c727071e8f11b0cc6d4572a42c9feb424d3be7f60703f
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ cities.txt
data/city_search.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'city_search'
3
- s.version = '0.0.1'
4
- s.date = '2017-10-17'
3
+ s.version = '0.0.2'
4
+ s.date = '2019-04-30'
5
5
  s.summary = "City Search"
6
6
  s.description = "Finds cities"
7
7
  s.authors = ["Maksatbek Mansurov"]
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
- module CitySearch
3
- extend self
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 = dawg.query(q)
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 = result + states[code.to_i]
16
+ result += states[code.to_i]
11
17
  end
12
18
  end
13
19
 
14
- private
20
+ def country_exists?(country)
21
+ File.exists?(File.dirname(__FILE__) + "/../data/#{country}.bin")
22
+ end
15
23
 
16
- def dawg
17
- @@dawg ||= Dawg.load(File.dirname(__FILE__) + '/../data/dawg.bin', :fast)
24
+ def db
25
+ @all ||= Dawg.load(File.dirname(__FILE__) + "/../data/#{@country}.bin")
18
26
  end
19
27
 
20
28
  def states
21
- @@states ||= Marshal.load(File.read(File.dirname(__FILE__) + '/../data/state-countries.bin'))
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.1
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: 2017-10-17 00:00:00.000000000 Z
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/dawg.bin
41
- - data/state-countries.bin
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.4.5.1
66
+ rubygems_version: 2.7.6
64
67
  signing_key:
65
68
  specification_version: 4
66
69
  summary: City Search