iso3166_ru 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -17
- data/iso3166_ru.gemspec +1 -0
- data/lib/iso3166_ru.rb +1 -1
- data/lib/iso3166_ru/country_list.rb +7 -7
- data/lib/iso3166_ru/version.rb +1 -1
- data/test/iso3166_ru_test.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ac8ba9920bc84e46cebb8198fad7d773af5bd95
|
4
|
+
data.tar.gz: eded2644c25134f4b2fce892c755a24601097cb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d118e53e5fee42cea08b5606574b4cc924f63e0051878a5257df3101db71b2f10f462619495c4c8c2adac1bcc47148382170aa1a5a72f95be4bc7865ed53522a
|
7
|
+
data.tar.gz: cfa69a2eabccd7b5745f6a5ba19471b0bf4517dfc7827676c10fe0792a71da6378c1850f4862c66ccd0f739fa9c08f581e09ca2b47a574ccf5914ca18442c405
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'iso3166_ru'
|
9
|
+
gem 'iso3166_ru', '~> 0.2.0'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
###
|
21
|
+
### Country finders
|
22
22
|
|
23
23
|
Iso3166Ru.find_by(alpha2: "RU")
|
24
24
|
Iso3166Ru.find_by(alpha3: "RUS")
|
@@ -27,21 +27,6 @@ Or install it yourself as:
|
|
27
27
|
Iso3166Ru.find_by(english: "Russian Federation")
|
28
28
|
Iso3166Ru.find_by(iso: "643")
|
29
29
|
|
30
|
-
### Performant finding
|
31
|
-
|
32
|
-
If you don't want to load country data for each request, you can initialize `Iso3166Ru::CountryList` and use it:
|
33
|
-
|
34
|
-
country_list = Iso3166Ru::CountryList.new
|
35
|
-
|
36
|
-
country_list.find_by(alpha2: "RU")
|
37
|
-
country_list.find_by(alpha3: "RUS")
|
38
|
-
country_list.find_by(name: "Россия")
|
39
|
-
country_list.find_by(full_name: "Российская Федерация")
|
40
|
-
country_list.find_by(english: "Russian Federation")
|
41
|
-
country_list.find_by(iso: "643")
|
42
|
-
|
43
|
-
This chops away ~99.8% of execution time.
|
44
|
-
|
45
30
|
All finders return an `Iso3166Ru::Country` struct.
|
46
31
|
|
47
32
|
### Country
|
data/iso3166_ru.gemspec
CHANGED
data/lib/iso3166_ru.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require "iso3166_ru/country"
|
2
|
+
require 'singleton'
|
2
3
|
|
3
4
|
module Iso3166Ru
|
4
5
|
class CountryList
|
5
|
-
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_reader :countries, :indexes
|
6
9
|
|
7
10
|
def initialize
|
8
11
|
File.open(File.expand_path("../data.dat", __FILE__)) do |f|
|
9
|
-
@
|
12
|
+
@countries, @indexes = Marshal.load(f)
|
10
13
|
end
|
11
|
-
|
12
|
-
@countries = data[0]
|
13
|
-
@indexes = data[1]
|
14
14
|
end
|
15
15
|
|
16
16
|
def find_by(query)
|
@@ -22,8 +22,8 @@ module Iso3166Ru
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def prepare_query(query)
|
25
|
-
key = query.
|
26
|
-
value =
|
25
|
+
key, value = query.first
|
26
|
+
value = "%03d" % value.to_i if key == :iso
|
27
27
|
|
28
28
|
[key, value]
|
29
29
|
end
|
data/lib/iso3166_ru/version.rb
CHANGED
data/test/iso3166_ru_test.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require "minitest_helper"
|
4
4
|
require "iso3166_ru"
|
5
5
|
|
6
|
-
class Iso3166RuTest <
|
6
|
+
class Iso3166RuTest < Minitest::Test
|
7
7
|
RUSSIA = Iso3166Ru::Country.new("Россия", "Российская Федерация",
|
8
8
|
"Russian Federation", "RU", "RUS", "643", "Европа", "Восточная Европа")
|
9
9
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iso3166_ru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Shitov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.0.6
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.0.6
|
41
55
|
description: Lets you find country names in English and Russian, based on country
|
42
56
|
codes (and vice versa)
|
43
57
|
email:
|