iso3166_ru 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 907e4c918d78b9da7c11543c79a355af4363daa6
4
+ data.tar.gz: 2d5ae4a8fbe1d2e8b391878ed2b6fe893447e2e7
5
+ SHA512:
6
+ metadata.gz: 939f126613d6cc41defa32b218d924a165780b13e5e230eec4b0f6ea0bb518da5306cfe23d847914e7cb321eeff2d14e14cada754c6936728ce1b0ac8290f75a
7
+ data.tar.gz: 74a7dc8ddd6160e35ac1afba8a599a92d82d32d5f125719ea50ce60644287407def7b5e4601cfac193f3d25838cc1814737f73626f3f378eca50692430b83019
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iso3166_ru.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Artem Shitov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # ISO 3166-1 Country List in English and Russian
2
+
3
+ [![Build Status](https://travis-ci.org/artemshitov/iso3166_ru.png?branch=master)](https://travis-ci.org/artemshitov/iso3166_ru) [![Code Climate](https://codeclimate.com/github/artemshitov/iso3166_ru.png)](https://codeclimate.com/github/artemshitov/iso3166_ru)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'iso3166_ru'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install iso3166_ru
18
+
19
+ ## Usage
20
+
21
+ ### Simple ActiveRecord-alike finders
22
+
23
+ Iso3166Ru.find_by(alpha2: "RU")
24
+ Iso3166Ru.find_by(alpha3: "RUS")
25
+ Iso3166Ru.find_by(name: "Россия")
26
+ Iso3166Ru.find_by(full_name: "Российская Федерация")
27
+ Iso3166Ru.find_by(english: "Russian Federation")
28
+ Iso3166Ru.find_by(iso: "643")
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
+ All finders return an `Iso3166Ru::Country` struct.
44
+
45
+ ### Country
46
+
47
+ country = Iso3166Ru.find_by(alpha2: "RU")
48
+
49
+ country.alpha2 #=> "RU"
50
+ country.alpha3 #=> "RUS"
51
+ country.name #=> "Россия"
52
+ country.full_name #=> "Российская Федерация"
53
+ country.english #=> "Russian Federation"
54
+ country.iso #=> "643"
55
+ country.location #=> "Европа"
56
+ country.location_precise #=> "Восточная Европа"
57
+
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ require "net/http"
7
+
8
+ require "iso3166_ru/country"
9
+
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << "test"
12
+ t.test_files = FileList['test/*_test.rb', 'test/*/*_test.rb']
13
+ end
14
+
15
+ namespace :countries do
16
+ task :update do
17
+ doc = Net::HTTP.get("www.artlebedev.ru", "/tools/country-list/tab/").force_encoding("UTF-8")
18
+ raw_data = doc.split("\n")[1..-1].map { |c| c.split("\t") }
19
+ countries = raw_data.reduce([]) { |a, e| a << Iso3166Ru::CountryFactory.build(e) }
20
+
21
+ File.open(File.expand_path("../lib/iso3166_ru/data.dat", __FILE__), "w") do |f|
22
+ f.write Marshal.dump(countries)
23
+ end
24
+ end
25
+ end
26
+
27
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'iso3166_ru/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "iso3166_ru"
8
+ spec.version = Iso3166Ru::VERSION
9
+ spec.authors = ["Artem Shitov"]
10
+ spec.email = ["inbox@artemshitov.ru"]
11
+ spec.description = %q{Lets you find country names in English and Russian, based on country codes (and vice versa)}
12
+ spec.summary = %q{ISO 3166-1 country list in English and Russian}
13
+ spec.homepage = "https://github.com/artemshitov/iso3166_ru"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/lib/iso3166_ru.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "iso3166_ru/version"
2
+ require "iso3166_ru/country_list"
3
+
4
+ module Iso3166Ru
5
+ def self.find_by(query)
6
+ CountryList.new.find_by(query)
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module Iso3166Ru
2
+ Country = Struct.new(:name, :full_name, :english, :alpha2, :alpha3, :iso,
3
+ :location, :location_precise)
4
+
5
+ module CountryFactory
6
+ def self.build(country_config)
7
+ Country.new(*country_config)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ require "iso3166_ru/country"
2
+
3
+ module Iso3166Ru
4
+ class CountryList
5
+ attr_reader :countries
6
+
7
+ def initialize
8
+ File.open(File.expand_path("../data.dat", __FILE__)) do |f|
9
+ @countries = Marshal.load(f)
10
+ end
11
+ end
12
+
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
+ end
17
+ end
18
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ module Iso3166Ru
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require "minitest_helper"
4
+ require "iso3166_ru"
5
+
6
+ class Iso3166RuTest < MiniTest::Unit::TestCase
7
+ RUSSIA = Iso3166Ru::Country.new("Россия", "Российская Федерация",
8
+ "Russian Federation", "RU", "RUS", "643", "Европа", "Восточная Европа")
9
+
10
+ def test_find_by_alpha2
11
+ assert_equal RUSSIA, Iso3166Ru.find_by(alpha2: "RU")
12
+ end
13
+
14
+ def test_find_by_alpha3
15
+ assert_equal RUSSIA, Iso3166Ru.find_by(alpha3: "RUS")
16
+ end
17
+
18
+ def test_find_by_name
19
+ assert_equal RUSSIA, Iso3166Ru.find_by(name: "Россия")
20
+ end
21
+
22
+ def test_find_by_full_name
23
+ assert_equal RUSSIA, Iso3166Ru.find_by(full_name: "Российская Федерация")
24
+ end
25
+
26
+ def test_find_by_english
27
+ assert_equal RUSSIA, Iso3166Ru.find_by(english: "Russian Federation")
28
+ end
29
+
30
+ def test_find_by_iso
31
+ assert_equal RUSSIA, Iso3166Ru.find_by(iso: "643")
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iso3166_ru
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Artem Shitov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Lets you find country names in English and Russian, based on country
42
+ codes (and vice versa)
43
+ email:
44
+ - inbox@artemshitov.ru
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - .travis.yml
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - iso3166_ru.gemspec
56
+ - lib/iso3166_ru.rb
57
+ - lib/iso3166_ru/country.rb
58
+ - lib/iso3166_ru/country_list.rb
59
+ - lib/iso3166_ru/data.dat
60
+ - lib/iso3166_ru/version.rb
61
+ - test/iso3166_ru_test.rb
62
+ - test/minitest_helper.rb
63
+ homepage: https://github.com/artemshitov/iso3166_ru
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.0.0
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: ISO 3166-1 country list in English and Russian
87
+ test_files:
88
+ - test/iso3166_ru_test.rb
89
+ - test/minitest_helper.rb