emoji_flag 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
+ SHA1:
3
+ metadata.gz: e3ecbf5458ed4f8bdb1a142d324ed43fb05665c6
4
+ data.tar.gz: 3070d84906e3d9c815172e6ad1168196f0af57f6
5
+ SHA512:
6
+ metadata.gz: 7097b7cd6a9cdf2ecdad756ab94c30a8973c8d095a4e9f054440c0d554825c4e689b11338f030bad733be9503c330eca0d3be36f2e3677d8a66bcc6c8ef0e2d4
7
+ data.tar.gz: 4842cc0fdb4827e0b210333194f1e763eb4b57b3202646a9b0788be8aa798a8918f29edf2f16615f00a789ad48b470617af4a4150ae0c84157e628f28d656dc9
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ # osx noise
2
+ .DS_Store
3
+ profile
4
+ coverage
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.10
5
+ - 2.2.6
6
+ - 2.3.1
7
+ - 2.4.0
8
+
9
+ addons:
10
+ code_climate:
11
+ repo_token: 5db559a56b2ea09902ff8bcb2ba495b5089c76205024362a798f9cf88d38db32
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'codeclimate-test-reporter', '~> 1.0.0'
7
+ gem 'simplecov'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ emoji_flag (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ codeclimate-test-reporter (1.0.6)
10
+ simplecov
11
+ coderay (1.1.1)
12
+ docile (1.1.5)
13
+ ffi (1.9.17)
14
+ formatador (0.2.5)
15
+ guard (2.14.1)
16
+ formatador (>= 0.2.4)
17
+ listen (>= 2.7, < 4.0)
18
+ lumberjack (~> 1.0)
19
+ nenv (~> 0.1)
20
+ notiffany (~> 0.0)
21
+ pry (>= 0.9.12)
22
+ shellany (~> 0.0)
23
+ thor (>= 0.18.1)
24
+ guard-compat (1.2.1)
25
+ guard-minitest (2.4.6)
26
+ guard-compat (~> 1.2)
27
+ minitest (>= 3.0)
28
+ json (2.0.3)
29
+ listen (3.1.5)
30
+ rb-fsevent (~> 0.9, >= 0.9.4)
31
+ rb-inotify (~> 0.9, >= 0.9.7)
32
+ ruby_dep (~> 1.2)
33
+ lumberjack (1.0.11)
34
+ method_source (0.8.2)
35
+ minitest (5.10.1)
36
+ nenv (0.3.0)
37
+ notiffany (0.1.1)
38
+ nenv (~> 0.1)
39
+ shellany (~> 0.0)
40
+ pry (0.10.4)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.8.1)
43
+ slop (~> 3.4)
44
+ rake (12.0.0)
45
+ rb-fsevent (0.9.8)
46
+ rb-inotify (0.9.8)
47
+ ffi (>= 0.5.0)
48
+ ruby_dep (1.4.0)
49
+ shellany (0.0.1)
50
+ simplecov (0.13.0)
51
+ docile (~> 1.1.0)
52
+ json (>= 1.8, < 3)
53
+ simplecov-html (~> 0.10.0)
54
+ simplecov-html (0.10.0)
55
+ slop (3.6.0)
56
+ thor (0.19.4)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ codeclimate-test-reporter (~> 1.0.0)
63
+ emoji_flag!
64
+ guard (~> 2.14)
65
+ guard-minitest (~> 2.4)
66
+ rake (~> 12.0)
67
+ simplecov
68
+
69
+ BUNDLED WITH
70
+ 1.14.5
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :minitest do
2
+ watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
3
+ watch(%r{^test/.+_test\.rb$})
4
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
5
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Richard Venneman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # EmojiFlag
2
+
3
+ A simple gem to get the [emoji flag](http://emojipedia.org/flags/) for a [ISO 639-1 language code](http://www.loc.gov/standards/iso639-2/php/English_list.php) or locale id string (LCID).
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ EmojiFlag.new('nl') # => πŸ‡³πŸ‡±
9
+ EmojiFlag.new('en') # => πŸ‡¬πŸ‡§
10
+ EmojiFlag.new('nl_BE') # => πŸ‡§πŸ‡ͺ
11
+ EmojiFlag.new('en_US') # => πŸ‡ΊπŸ‡Έ
12
+ ```
13
+
14
+ Also supports passing in a symbol language code, making it easy to integrate with Rails' `I18n.available_locale`:
15
+
16
+ ```ruby
17
+ EmojiFlag.new(:de) # => πŸ‡©πŸ‡ͺ
18
+ ```
19
+
20
+ ## Installation
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'emoji_flag'
25
+ ```
26
+
27
+ And then execute:
28
+ ```bash
29
+ $ bundle
30
+ ```
31
+
32
+ ## License
33
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new(:test) do |t|
4
+ t.libs << 'lib'
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ t.verbose = false
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,19 @@
1
+ require './lib/emoji_flag/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'emoji_flag'
5
+ s.version = EmojiFlag::VERSION
6
+ s.license = 'MIT'
7
+ s.authors = ['Richard Venneman']
8
+ s.email = 'richardvenneman@me.com'
9
+ s.homepage = 'https://github.com/richardvenneman/emoji_flag'
10
+ s.summary = 'Emoji country flags for language codes.'
11
+ s.description = 'Returns the emoji flag for a ISO 639-1 language code or LCID.'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = Dir['test/**/*']
15
+
16
+ s.add_development_dependency 'rake', '~> 12.0'
17
+ s.add_development_dependency 'guard', '~> 2.14'
18
+ s.add_development_dependency 'guard-minitest', '~> 2.4'
19
+ end
@@ -0,0 +1,166 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EmojiFlag
4
+ # Thankfully taken from: https://github.com/10xjs/locale-emoji
5
+ DEFAULTS = {
6
+ af: 'ZA',
7
+ agq: 'CM',
8
+ ak: 'GH',
9
+ am: 'ET',
10
+ ar: 'AE',
11
+ as: 'IN',
12
+ asa: 'TZ',
13
+ az: 'AZ',
14
+ bas: 'CM',
15
+ be: 'BY',
16
+ bem: 'ZM',
17
+ bez: 'IT',
18
+ bg: 'BG',
19
+ bm: 'ML',
20
+ bn: 'BD',
21
+ bo: 'CN',
22
+ br: 'FR',
23
+ brx: 'IN',
24
+ bs: 'BA',
25
+ ca: 'ES',
26
+ cgg: 'UG',
27
+ chr: 'US',
28
+ cs: 'CZ',
29
+ cy: 'GB',
30
+ da: 'DK',
31
+ dav: 'KE',
32
+ de: 'DE',
33
+ dje: 'NE',
34
+ dua: 'CM',
35
+ dyo: 'SN',
36
+ ebu: 'KE',
37
+ ee: 'GH',
38
+ en: 'GB',
39
+ el: 'GR',
40
+ es: 'ES',
41
+ et: 'EE',
42
+ eu: 'ES',
43
+ ewo: 'CM',
44
+ fa: 'IR',
45
+ fil: 'PH',
46
+ fr: 'FR',
47
+ ga: 'IE',
48
+ gl: 'ES',
49
+ gsw: 'CH',
50
+ gu: 'IN',
51
+ guz: 'KE',
52
+ gv: 'GB',
53
+ ha: 'NG',
54
+ haw: 'US',
55
+ he: 'IL',
56
+ hi: 'IN',
57
+ ff: 'CN',
58
+ fi: 'FI',
59
+ fo: 'FO',
60
+ hr: 'HR',
61
+ hu: 'HU',
62
+ hy: 'AM',
63
+ id: 'ID',
64
+ ig: 'NG',
65
+ ii: 'CN',
66
+ is: 'IS',
67
+ it: 'IT',
68
+ ja: 'JP',
69
+ jmc: 'TZ',
70
+ ka: 'GE',
71
+ kab: 'DZ',
72
+ ki: 'KE',
73
+ kam: 'KE',
74
+ mer: 'KE',
75
+ kde: 'TZ',
76
+ kea: 'CV',
77
+ khq: 'ML',
78
+ kk: 'KZ',
79
+ kl: 'GL',
80
+ kln: 'KE',
81
+ km: 'KH',
82
+ kn: 'IN',
83
+ ko: 'KR',
84
+ kok: 'IN',
85
+ ksb: 'TZ',
86
+ ksf: 'CM',
87
+ kw: 'GB',
88
+ lag: 'TZ',
89
+ lg: 'UG',
90
+ ln: 'CG',
91
+ lt: 'LT',
92
+ lu: 'CD',
93
+ lv: 'LV',
94
+ luo: 'KE',
95
+ luy: 'KE',
96
+ mas: 'TZ',
97
+ mfe: 'MU',
98
+ mg: 'MG',
99
+ mgh: 'MZ',
100
+ ml: 'IN',
101
+ mk: 'MK',
102
+ mr: 'IN',
103
+ ms: 'MY',
104
+ mt: 'MT',
105
+ mua: 'CM',
106
+ my: 'MM',
107
+ naq: 'NA',
108
+ nb: 'NO',
109
+ nd: 'ZW',
110
+ ne: 'NP',
111
+ nl: 'NL',
112
+ nmg: 'CM',
113
+ nn: 'NO',
114
+ nus: 'SD',
115
+ nyn: 'UG',
116
+ om: 'ET',
117
+ or: 'IN',
118
+ pa: 'PK',
119
+ pl: 'PL',
120
+ ps: 'AF',
121
+ pt: 'PT',
122
+ rm: 'CH',
123
+ rn: 'BI',
124
+ ro: 'RO',
125
+ ru: 'RU',
126
+ rw: 'RW',
127
+ rof: 'TZ',
128
+ rwk: 'TZ',
129
+ saq: 'KE',
130
+ sbp: 'TZ',
131
+ seh: 'MZ',
132
+ ses: 'ML',
133
+ sg: 'CF',
134
+ shi: 'MA',
135
+ si: 'LK',
136
+ sk: 'SK',
137
+ sl: 'SI',
138
+ sn: 'ZW',
139
+ so: 'SO',
140
+ sq: 'AL',
141
+ sr: 'RS',
142
+ sv: 'SE',
143
+ sw: 'TZ',
144
+ swc: 'CD',
145
+ ta: 'IN',
146
+ te: 'IN',
147
+ teo: 'UG',
148
+ th: 'TH',
149
+ ti: 'ET',
150
+ to: 'TO',
151
+ tr: 'TR',
152
+ twq: 'NE',
153
+ tzm: 'MA',
154
+ uk: 'UA',
155
+ ur: 'PK',
156
+ uz: 'UZ',
157
+ vai: 'LR',
158
+ vi: 'VN',
159
+ vun: 'TZ',
160
+ xog: 'UG',
161
+ yav: 'CM',
162
+ yo: 'NG',
163
+ zh: 'CN',
164
+ zu: 'ZA'
165
+ }.freeze
166
+ end
@@ -0,0 +1,3 @@
1
+ module EmojiFlag
2
+ VERSION = '0.0.1'
3
+ end
data/lib/emoji_flag.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'emoji_flag/defaults'
4
+
5
+ module EmojiFlag
6
+ OFFSET = 127_397
7
+ COUNTRY_CODE_RE = /^[A-Z]{2}$/
8
+
9
+ def self.new(input)
10
+ locale = input.to_s
11
+ return '' if locale.nil? || locale.size.zero?
12
+
13
+ code = code_for_locale(locale)
14
+
15
+ code.codepoints.collect { |codepoint| codepoint + OFFSET }.pack('U*')
16
+ end
17
+
18
+ def self.code_for_locale(locale)
19
+ split = locale.upcase.split(/-|_/)
20
+ lang = split.shift
21
+ code = split.pop
22
+ code = DEFAULTS[lang.downcase.to_sym] unless COUNTRY_CODE_RE.match(code)
23
+
24
+ code || ''
25
+ end
26
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class EmojiFlagTest < Minitest::Test
6
+ def test_constructor
7
+ assert_equal true, EmojiFlag.respond_to?(:new)
8
+ end
9
+
10
+ def test_empty_code_returns_empty_string
11
+ assert_equal '', EmojiFlag.new(nil)
12
+ assert_equal '', EmojiFlag.new('')
13
+ end
14
+
15
+ def test_invalid_code_returns_empty_string
16
+ assert_equal '', EmojiFlag.new('derp')
17
+ end
18
+
19
+ def test_iso_3166_1_code_for_locale
20
+ assert_equal 'NL', EmojiFlag.code_for_locale('nl')
21
+ assert_equal 'GB', EmojiFlag.code_for_locale('en')
22
+ end
23
+
24
+ def test_lcid_code_for_locale
25
+ assert_equal 'NL', EmojiFlag.code_for_locale('nl_NL')
26
+ assert_equal 'GB', EmojiFlag.code_for_locale('en_GB')
27
+ assert_equal 'US', EmojiFlag.code_for_locale('en_US')
28
+ end
29
+
30
+ def test_valid_iso_3166_1_emoji
31
+ assert_equal 'πŸ‡³πŸ‡±', EmojiFlag.new('nl')
32
+ assert_equal 'πŸ‡ΈπŸ‡ͺ', EmojiFlag.new('SV')
33
+ end
34
+
35
+ def test_valid_iso_3166_1_symbol_emoji
36
+ assert_equal 'πŸ‡©πŸ‡ͺ', EmojiFlag.new(:de)
37
+ assert_equal 'πŸ‡―πŸ‡΅', EmojiFlag.new(:JA)
38
+ end
39
+
40
+ def test_valid_lcid_emoji
41
+ assert_equal 'πŸ‡³πŸ‡±', EmojiFlag.new('nl_NL')
42
+ assert_equal 'πŸ‡§πŸ‡ͺ', EmojiFlag.new('nl_BE')
43
+ assert_equal 'πŸ‡¬πŸ‡§', EmojiFlag.new('en_GB')
44
+ end
45
+
46
+ def test_valid_lcid_symbol_emoji
47
+ assert_equal 'πŸ‡ΊπŸ‡Έ', EmojiFlag.new(:en_US)
48
+ end
49
+ end
@@ -0,0 +1,16 @@
1
+ # Coverage
2
+ if ENV['CODECLIMATE_REPO_TOKEN']
3
+ require 'codeclimate-test-reporter'
4
+ CodeClimate::TestReporter.start
5
+ elsif ENV['COVERAGE']
6
+ require 'simplecov'
7
+ SimpleCov.start do
8
+ add_group 'Libraries', 'lib'
9
+ end
10
+ end
11
+
12
+ # Source files
13
+ require './lib/emoji_flag'
14
+
15
+ # Framework
16
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emoji_flag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard Venneman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ description: Returns the emoji flag for a ISO 639-1 language code or LCID.
56
+ email: richardvenneman@me.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - ".ruby-version"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - Guardfile
67
+ - MIT-LICENSE
68
+ - README.md
69
+ - Rakefile
70
+ - emoji_flag.gemspec
71
+ - lib/emoji_flag.rb
72
+ - lib/emoji_flag/defaults.rb
73
+ - lib/emoji_flag/version.rb
74
+ - test/lib/emoji_flag_test.rb
75
+ - test/test_helper.rb
76
+ homepage: https://github.com/richardvenneman/emoji_flag
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Emoji country flags for language codes.
100
+ test_files:
101
+ - test/lib/emoji_flag_test.rb
102
+ - test/test_helper.rb