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 +4 -4
- data/Rakefile +9 -1
- data/lib/iso3166_ru/country_list.rb +9 -5
- data/lib/iso3166_ru/data.dat +0 -0
- data/lib/iso3166_ru/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b5c459dbc4c712b2d6c92d9927f0b1f9f83fee19
|
|
4
|
+
data.tar.gz: 039c3fc12fcdebc36efadf6f4426582ba03e2d80
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
@
|
|
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(
|
|
14
|
-
|
|
15
|
-
|
|
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
|
data/lib/iso3166_ru/data.dat
CHANGED
|
Binary file
|
data/lib/iso3166_ru/version.rb
CHANGED