iso3166_ru 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 907e4c918d78b9da7c11543c79a355af4363daa6
4
- data.tar.gz: 2d5ae4a8fbe1d2e8b391878ed2b6fe893447e2e7
3
+ metadata.gz: b5c459dbc4c712b2d6c92d9927f0b1f9f83fee19
4
+ data.tar.gz: 039c3fc12fcdebc36efadf6f4426582ba03e2d80
5
5
  SHA512:
6
- metadata.gz: 939f126613d6cc41defa32b218d924a165780b13e5e230eec4b0f6ea0bb518da5306cfe23d847914e7cb321eeff2d14e14cada754c6936728ce1b0ac8290f75a
7
- data.tar.gz: 74a7dc8ddd6160e35ac1afba8a599a92d82d32d5f125719ea50ce60644287407def7b5e4601cfac193f3d25838cc1814737f73626f3f378eca50692430b83019
6
+ metadata.gz: 379e98949ac90374a99fd2f131c59fa65049549637585709eabd2da0a28602d4e99168b088e61b255428f5363d1089e69b3b9eef6d0cc48f92c684595a922000
7
+ data.tar.gz: b05d415327164e74149960cf4f3d7d70391d9321a9ec70643705ca37569545b3b9b606cb8d3ada49e07276cb93d7a2f6b8286dd3b6ff4561a85469db335fbb57
data/Rakefile CHANGED
@@ -17,9 +17,17 @@ namespace :countries do
17
17
  doc = Net::HTTP.get("www.artlebedev.ru", "/tools/country-list/tab/").force_encoding("UTF-8")
18
18
  raw_data = doc.split("\n")[1..-1].map { |c| c.split("\t") }
19
19
  countries = raw_data.reduce([]) { |a, e| a << Iso3166Ru::CountryFactory.build(e) }
20
+
21
+ indexes = Iso3166Ru::Country.members.reduce({}) { |a, e| a.merge(e => {}) }
22
+ a = []
23
+ countries.each_with_index do |e, i|
24
+ Iso3166Ru::Country.members.each do |k|
25
+ indexes[k] = indexes[k].merge({e[k] => i})
26
+ end
27
+ end
20
28
 
21
29
  File.open(File.expand_path("../lib/iso3166_ru/data.dat", __FILE__), "w") do |f|
22
- f.write Marshal.dump(countries)
30
+ f.write Marshal.dump([countries, indexes])
23
31
  end
24
32
  end
25
33
  end
@@ -2,17 +2,21 @@ require "iso3166_ru/country"
2
2
 
3
3
  module Iso3166Ru
4
4
  class CountryList
5
- attr_reader :countries
5
+ attr_reader :data, :countries, :indexes
6
6
 
7
7
  def initialize
8
8
  File.open(File.expand_path("../data.dat", __FILE__)) do |f|
9
- @countries = Marshal.load(f)
9
+ @data = Marshal.load(f)
10
10
  end
11
+
12
+ @countries = data[0]
13
+ @indexes = data[1]
11
14
  end
12
15
 
13
- def find_by(source_query)
14
- query = source_query.to_a.flatten
15
- countries.select { |e| e.send(query[0]) == query[1] }.first
16
+ def find_by(query)
17
+ k = query.keys[0]
18
+ q = query[k]
19
+ countries[indexes[k][q]]
16
20
  end
17
21
  end
18
22
  end
Binary file
@@ -1,3 +1,3 @@
1
1
  module Iso3166Ru
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iso3166_ru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Shitov