kokki 0.1.0

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: 5cd7e44e732d1879a894904016fe02838d013ecfbceff687d33a6778d42b09a5
4
+ data.tar.gz: 6f4055a63221e0d307715bae5135454bea0b2a0560e7deb359be087bfd328cd1
5
+ SHA512:
6
+ metadata.gz: 9782bcc594671ee16f5a5283d646988c33f2a33260629113288f4f7be17d9bfa1ec746a45847b9a43b02e354d23491b6c3bd04098a6def938b4fc96aaa0a0160
7
+ data.tar.gz: b36d9ed35c10f5534e0a547f08c729f5f5c686fd9c5faf27ff7016f6f5b4f01560f4be3807b98926fe3516c4e5ab2f07c79de8f987e3ea7bb27b73e537013a54
data/.gitignore ADDED
@@ -0,0 +1,52 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6
7
+ before_install:
8
+ - gem update --system
9
+ - gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in kokki.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Manabu Niseki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # kokki
2
+
3
+ [![Build Status](https://travis-ci.org/ninoseki/kokki.svg?branch=master)](https://travis-ci.org/ninoseki/kokki)
4
+ [![Coverage Status](https://coveralls.io/repos/github/ninoseki/kokki/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/kokki?branch=master)
5
+
6
+ A Ruby gem for converting a country name / code & IP address to an emoji flag.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ gem install kokki
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ruby
17
+ require "kokki"
18
+
19
+ puts "JP: #{Kokki.flagize('JP')}"
20
+ # => JP: 🇯🇵
21
+ puts "JPN: #{Kokki.flagize('JPN')}"
22
+ # => JPN: 🇯🇵
23
+ puts "Japan: #{Kokki.flagize('Japan')}"
24
+ # => Japan: 🇯🇵
25
+ puts "202.214.194.147: #{Kokki.flagize('202.214.194.147')}"
26
+ # => 202.214.194.147: 🇯🇵
27
+
28
+ begin
29
+ Kokki.flagize("test")
30
+ rescue Kokki::InvalidInputError => e
31
+ puts e.message
32
+ # => invalid input: test
33
+ end
34
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kokki"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/kokki.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "kokki/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "kokki"
9
+ spec.version = Kokki::VERSION
10
+ spec.authors = ["Manabu Niseki"]
11
+ spec.email = ["manabu.niseki@gmail.com"]
12
+
13
+ spec.summary = "Convert a country name / code & IP address to an emoji flag"
14
+ spec.description = "Convert a country name / code & IP address to an emoji flag"
15
+ spec.homepage = "https://github.com/ninoseki/kokki"
16
+ spec.license = "MIT"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "coveralls", "~> 0.8"
29
+ spec.add_development_dependency "rake", "~> 12.3"
30
+ spec.add_development_dependency "rspec", "~> 3.8"
31
+ spec.add_development_dependency "vcr", "~> 4.0"
32
+ spec.add_development_dependency "webmock", "~> 3.5"
33
+
34
+ spec.add_dependency "geocoder", "~> 1.5"
35
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ipaddr"
4
+
5
+ module Kokki
6
+ class Converter
7
+ attr_reader :input, :upcase, :dict
8
+
9
+ def initialize(input)
10
+ @input = input
11
+ @upcase = input.upcase
12
+ @dict = Dictionary.new
13
+ end
14
+
15
+ def convert
16
+ flag = nil
17
+
18
+ flag = dict.lookup_by_alpha_2_code(upcase) if input.length == 2
19
+ flag = dict.lookup_by_alpha_3_code(upcase) if input.length == 3
20
+ flag ||= dict.lookup_by_name(upcase)
21
+ flag ||= convert_as_ip_address(input)
22
+
23
+ raise InvalidInputError, "invalid input: #{input}" unless flag
24
+
25
+ flag
26
+ end
27
+
28
+ def self.convert(input)
29
+ new(input).convert
30
+ end
31
+
32
+ private
33
+
34
+ def convert_as_ip_address(ip_address)
35
+ ip = IPAddress.new(ip_address)
36
+ dict.lookup_by_alpha_2_code ip.country_code
37
+ end
38
+ end
39
+ end