iso3166_ru 0.1.2 → 0.2.0

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: a8fe43ebdc3f7044480975473a8492dc8cdb9a51
4
- data.tar.gz: 7c340d166f4bcd3450c580e570848f3a5a64b1fb
3
+ metadata.gz: 9ac8ba9920bc84e46cebb8198fad7d773af5bd95
4
+ data.tar.gz: eded2644c25134f4b2fce892c755a24601097cb6
5
5
  SHA512:
6
- metadata.gz: 004572b9ddbe5dd03dde5471370146934a788176a6c42982c6ab328c78d1d698ecd5856f25748f65dbfa02855c12da7a310ded1895da2246df9273ec3c1aae47
7
- data.tar.gz: f34633d7bfc9e5f368d9ad2bda4e9b340d64e8392aed2a6e845eb61156f60a021ea8c5759f2b4da4dc1a4332c1442750f95663f3c15d87941d39740e46a43143
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
- ### Simple ActiveRecord-alike finders
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
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'minitest', '~> 5.0.6'
23
24
  end
@@ -3,6 +3,6 @@ require "iso3166_ru/country_list"
3
3
 
4
4
  module Iso3166Ru
5
5
  def self.find_by(query)
6
- CountryList.new.find_by(query)
6
+ CountryList.instance.find_by(query)
7
7
  end
8
8
  end
@@ -1,16 +1,16 @@
1
1
  require "iso3166_ru/country"
2
+ require 'singleton'
2
3
 
3
4
  module Iso3166Ru
4
5
  class CountryList
5
- attr_reader :data, :countries, :indexes
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
- @data = Marshal.load(f)
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.keys.first
26
- value = key == :iso ? "%03d" % query[key].to_i : query[key]
25
+ key, value = query.first
26
+ value = "%03d" % value.to_i if key == :iso
27
27
 
28
28
  [key, value]
29
29
  end
@@ -1,3 +1,3 @@
1
1
  module Iso3166Ru
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,7 +3,7 @@
3
3
  require "minitest_helper"
4
4
  require "iso3166_ru"
5
5
 
6
- class Iso3166RuTest < MiniTest::Unit::TestCase
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.1.2
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-05-07 00:00:00.000000000 Z
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: