llaxta 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e9bbf0a82b338dcce0967b82a162b6fdbf6991436771641c1a67e108995c0879
4
+ data.tar.gz: d6799b66953da5df87e6e3af83e27cd8bf77ec01222e3d6c309c25bfef240c53
5
+ SHA512:
6
+ metadata.gz: 814808049396b86c29212f8fa07d4e13c0c11527b5d8613a581872f2cbe8f4ada21c178a72211383c40c827dec4e93a4d7c6533399b7690409b85f27e6381bcc
7
+ data.tar.gz: '03429b9e5957abdbeead30e176fdbf69d29388129b439e1653f5623a87ebfc43f0083f0ba8f0dd9415ae816d07c1061875b3f5b34c86da0352198e0908f56004'
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ .DS_Store
2
+ .idea
3
+ .ruby-version
4
+ .tool-versions
5
+ gemfiles/*.lock
6
+ *.gem
7
+ *.rbc
8
+ .bundle
9
+ .config
10
+ .yardoc
11
+ Gemfile.lock
12
+ InstalledFiles
13
+ _yardoc
14
+ coverage
15
+ doc/
16
+ lib/bundler/man
17
+ pkg
18
+ rdoc
19
+ spec/reports
20
+ test/tmp
21
+ test/version_tmp
22
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper --color
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.0.1 (June 8, 2021)
2
+
3
+ - Initial commit
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ Get the name of any of the 249 countries listed in English US, Spanish, Brazilian Portuguese and/or Simplified Chinese.
2
+
3
+ ### Usage
4
+
5
+ There's an only public method called `t` which receives the country Alpha2 code and the locale corresponding to the language in which the country name is going to be shown.
6
+
7
+ ```ruby
8
+ LLaxta.t("CH", "en_us") # => "Switzerland"
9
+ LLaxta.t("CH", "es") # => "Suiza"
10
+ LLaxta.t("CH", "pt_br") # => "Suíça"
11
+ LLaxta.t("CH", "zh_cn") # => "瑞士"
12
+ ```
13
+
14
+ For convenience, and because there's only 4 supported locales, you can use the short version of the languages English (`us`), Portuguese (`br`) and Chinese (`cn`):
15
+
16
+ ```ruby
17
+ LLaxta.t("CH", "us") # => "Switzerland"
18
+ LLaxta.t("CH", "br") # => "Suíça"
19
+ LLaxta.t("CH", "cn") # => "瑞士"
20
+ ```
data/lib/llaxta.rb ADDED
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "llaxta/exceptions"
5
+
6
+ class Llaxta
7
+ VERSION = Gem::Version.new("0.0.1")
8
+
9
+ class << self
10
+ def t(alpha2, locale)
11
+ raise Exceptions::AlphaMissing unless alpha2
12
+
13
+ dictionary(locale)[alpha2]
14
+ end
15
+
16
+ private
17
+
18
+ def dictionary(locale)
19
+ @@locales ||= {}
20
+ @@locales[locale] ||= new(locale).send(:load_dict)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :locale
27
+
28
+ SUPPORTED_LOCALES = {
29
+ "en_us" => "en_us",
30
+ "us" => "en_us",
31
+ "es" => "es",
32
+ "pt_br" => "pt_br",
33
+ "br" => "pt_br",
34
+ "zh_cn" => "zh_cn",
35
+ "cn" => "zh_cn",
36
+ }.freeze
37
+ private_constant :SUPPORTED_LOCALES
38
+
39
+ def initialize(locale)
40
+ raise Exceptions::LocaleMissing unless locale
41
+
42
+ @locale = SUPPORTED_LOCALES[locale]
43
+ end
44
+
45
+ def load_dict
46
+ YAML.load_file(locale_path)
47
+ rescue Errno::ENOENT
48
+ raise Exceptions::LocaleNotFound.new(locale)
49
+ end
50
+
51
+ def locale_path
52
+ File.expand_path("../llaxta/locales/#{locale}.yml", __FILE__)
53
+ end
54
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Exceptions
4
+ class AlphaMissing < StandardError
5
+ def initialize
6
+ super("Alpha can not be blank!")
7
+ end
8
+ end
9
+
10
+ class LocaleMissing < StandardError
11
+ def initialize
12
+ super("Locale can not be blank!")
13
+ end
14
+ end
15
+
16
+ class LocaleNotFound < StandardError
17
+ def initialize(locale)
18
+ super("Locale \"#{locale}\" was not found!")
19
+ end
20
+ end
21
+ end
data/llaxta.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "llaxta"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "llaxta"
7
+ spec.required_ruby_version = ">= 2.2.0"
8
+ spec.homepage = "https://github.com/kucho/llaxta"
9
+ spec.version = Llaxta::VERSION
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.summary = "Translate ISO 3166-1 codes to Country names given a locale"
12
+ spec.description = "Translate ISO 3166-1 codes to Country names given a locale"
13
+ spec.authors = ["Victor Rodriguez", "Sebastian Palma"]
14
+ spec.email = "victor.rodriguez.guriz@gmail.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.metadata = {
21
+ "source_code_uri" => "https://github.com/kucho/llaxta",
22
+ "changelog_uri" => "https://github.com/kucho/llaxta/blob/master/CHANGELOG.md"
23
+ }
24
+
25
+ spec.add_development_dependency("bundler", "~> 2.2")
26
+ spec.add_development_dependency("standard", "~> 1.0")
27
+ spec.add_development_dependency("rspec", "~> 3.10")
28
+ spec.add_development_dependency("pry", "~> 0.14.1")
29
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Llaxta do
4
+ describe ".t" do
5
+ context "when locale is valid" do
6
+ context "with locale en_us" do
7
+ it "returns the country name given the iso_code and locale" do
8
+ expect(Llaxta.t("CH", "en_us")).to eq("Switzerland")
9
+ end
10
+ end
11
+
12
+ context "with locale es" do
13
+ it "returns the country name given the iso_code and locale" do
14
+ expect(Llaxta.t("CH", "es")).to eq("Suiza")
15
+ end
16
+ end
17
+
18
+ context "with locale pt_br" do
19
+ it "returns the country name given the iso_code and locale" do
20
+ expect(Llaxta.t("CH", "pt_br")).to eq("Suíça")
21
+ end
22
+ end
23
+
24
+ context "with locale pt_br" do
25
+ it "returns the country name given the iso_code and locale" do
26
+ expect(Llaxta.t("CH", "zh_cn")).to eq("瑞士")
27
+ end
28
+ end
29
+ end
30
+
31
+ context "using a short-version locale" do
32
+ context "with locale us" do
33
+ it { expect(Llaxta.t("CH", "us")).to eq("Switzerland") }
34
+ end
35
+
36
+ context "with locale br" do
37
+ it { expect(Llaxta.t("CH", "br")).to eq("Suíça") }
38
+ end
39
+
40
+ context "with locale cn" do
41
+ it { expect(Llaxta.t("CH", "cn")).to eq("瑞士") }
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "exceptions" do
47
+ context "when locale is NOT valid" do
48
+ it "raises" do
49
+ expect { Llaxta.t("PE", "2GFA") }.to raise_exception Exceptions::LocaleNotFound
50
+ end
51
+ end
52
+
53
+ context "when alpha is nil" do
54
+ it "raises" do
55
+ expect { Llaxta.t(nil, "br") }.to raise_exception Exceptions::AlphaMissing
56
+ end
57
+ end
58
+
59
+ context "when locale is nil" do
60
+ it "raises" do
61
+ expect { Llaxta.t("PE", nil) }.to raise_exception Exceptions::LocaleMissing
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec"
4
+ require "llaxta"
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec do |c|
8
+ c.syntax = :expect # disables `should`
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: llaxta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Victor Rodriguez
8
+ - Sebastian Palma
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-06-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.2'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: standard
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.10'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.10'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.14.1
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.14.1
70
+ description: Translate ISO 3166-1 codes to Country names given a locale
71
+ email: victor.rodriguez.guriz@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - CHANGELOG.md
79
+ - Gemfile
80
+ - README.md
81
+ - lib/llaxta.rb
82
+ - lib/llaxta/exceptions.rb
83
+ - llaxta.gemspec
84
+ - spec/llaxta_spec.rb
85
+ - spec/spec_helper.rb
86
+ homepage: https://github.com/kucho/llaxta
87
+ licenses:
88
+ - MIT
89
+ metadata:
90
+ source_code_uri: https://github.com/kucho/llaxta
91
+ changelog_uri: https://github.com/kucho/llaxta/blob/master/CHANGELOG.md
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.2.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.2.15
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Translate ISO 3166-1 codes to Country names given a locale
111
+ test_files:
112
+ - spec/llaxta_spec.rb
113
+ - spec/spec_helper.rb