natophone 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: cc66af7ce5d5d06b5f361de80a33dabf020ee0e1
4
+ data.tar.gz: 791a88cbb58dcac56fc8cec7b4cdecc30712576b
5
+ SHA512:
6
+ metadata.gz: 6d3b3b03deb38d7ae7e97037821fae5689707327e51670dc5cbcb7e437ae39f21a3355ea5f5965478f9849a1f2cb181e7d46c3e0e12c6418947d1eae609c3880
7
+ data.tar.gz: abbc572696c83f6de710c0ea56cf379be711faa593ad9c04183382d8dee30d9764e3cc508df6d4de0d95e4e97505880a2d0f19026a0afdbbb9a17cd889927ebb
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - "2.1.2"
6
+ - "2.1.1"
7
+ - "2.1.0"
8
+ - "2.0.0"
9
+
10
+ script: 'rspec spec/spec_natophone.rb'
11
+
12
+ branches:
13
+ only:
14
+ - master
15
+
16
+ notifications:
17
+ email:
18
+ - ericdejonckheere@gmail.com
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in natophone.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eric Dejonckheere
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/NATOPhone.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require_relative 'lib/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "natophone"
8
+ spec.version = NATOPhone::VERSION
9
+ spec.authors = ["Eric Dejonckheere"]
10
+ spec.email = ["eric@aya.io"]
11
+ spec.summary = %q{Simple tool to encode/decode NATO alphabet.}
12
+ spec.description = %q{Simple tool to encode/decode NATO alphabet. Use as a CLI, or as a library for your apps.}
13
+ spec.homepage = "https://github.com/ericdke/NATOPhone"
14
+ spec.license = "MIT"
15
+
16
+ spec.bindir = 'bin'
17
+ spec.files = `git ls-files`.split("\n")
18
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ spec.executables = %w{natophone}
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "thor", "~> 0.18"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 2.14"
27
+ spec.add_development_dependency "rb-fsevent", "~> 0.9"
28
+ spec.add_development_dependency "guard-rspec", "~> 4.2"
29
+ spec.add_development_dependency "coveralls"
30
+ end
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # NATOPhone
2
+
3
+ Simple tool to encode/decode [NATO alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet).
4
+
5
+ ## Installation
6
+
7
+ ### CLI
8
+
9
+ $ gem install natophone
10
+
11
+ ### Library
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'natophone'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Usage
24
+
25
+ ### CLI
26
+
27
+ $ natophone encode Hello world.
28
+
29
+ $ natophone encode --yell Hello world.
30
+
31
+ $ natophone encode --json Hello world.
32
+
33
+ $ natophone decode hotel echo lima lima oscar - whiskey oscar romeo lima delta stop
34
+
35
+ $ natophone decode --yell hotel echo lima lima oscar - whiskey oscar romeo lima delta stop
36
+
37
+ $ natophone decode --json hotel echo lima lima oscar - whiskey oscar romeo lima delta stop
38
+
39
+ ### Library
40
+
41
+ ```ruby
42
+ enc = NATOPhone::Encoder.new(args)
43
+ puts enc.inspect
44
+ ```
45
+
46
+ ```ruby
47
+ dec = NATOPhone::Decoder.new(args)
48
+ puts dec.inspect
49
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/natophone ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: UTF-8
3
+
4
+ require_relative "../lib/version"
5
+ require_relative '../lib/app'
6
+
7
+ require "thor"
8
+
9
+ class NATOPhoneCLI < Thor
10
+
11
+ desc "encode WORD(S)", "Encode to NATO alphabet"
12
+ option :yell, aliases: '-Y', type: :boolean, desc: "Option to YELL the translation"
13
+ option :json, aliases: '-J', type: :boolean, desc: "Option to export the translation in JSON"
14
+ def encode(*args)
15
+ enc = NATOPhone::Encoder.new(args)
16
+ if options[:yell]
17
+ puts "\n#{enc.yell}\n\n"
18
+ elsif options[:json]
19
+ puts enc.to_json
20
+ else
21
+ puts "\n#{enc.translate}\n\n"
22
+ end
23
+ end
24
+
25
+ desc "decode NATO", "Decode from NATO alphabet"
26
+ option :yell, aliases: '-Y', type: :boolean, desc: "Option to YELL the translation"
27
+ option :json, aliases: '-J', type: :boolean, desc: "Option to export the translation in JSON"
28
+ def decode(*args)
29
+ dec = NATOPhone::Decoder.new(args)
30
+ if options[:yell]
31
+ puts "\n#{dec.yell}\n\n"
32
+ elsif options[:json]
33
+ puts dec.to_json
34
+ else
35
+ puts "\n#{dec.translate}\n\n"
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ NATOPhoneCLI.start(ARGV)
data/lib/app.rb ADDED
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module NATOPhone
5
+
6
+ require 'json'
7
+
8
+ class Base
9
+
10
+ attr_accessor :args, :translate, :yell
11
+
12
+ def initialize(args)
13
+ @args = args
14
+ end
15
+
16
+ private
17
+
18
+ def otan_alphabet_encode
19
+ { "a" => "alpha", "b" => "bravo", "c" => "charlie", "d" => "delta", "e" => "echo", "f" => "foxtrot", "g" => "golf", "h" => "hotel", "i" => "india", "j" => "juliet", "k" => "kilo", "l" => "lima", "m" => "mike", "n" => "november", "o" => "oscar", "p" => "papa", "q" => "quebec", "r" => "romeo", "s" => "sierra", "t" => "tango", "u" => "uniform", "v" => "victor", "w" => "whiskey", "x" => "x-ray", "y" => "yankee", "z" => "zulu", "0" => "zero", "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five", "6" => "six", "7" => "seven", "8" => "eight", "9" => "niner", " " => "-", "." => "stop" }
20
+ end
21
+
22
+ def otan_alphabet_decode
23
+ otan_alphabet_encode.invert
24
+ end
25
+
26
+ def sanitize(string)
27
+ string.tr "ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž", "AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz"
28
+ end
29
+
30
+ end # End of class Base
31
+
32
+ class Encoder < Base
33
+
34
+ attr_accessor :encode
35
+
36
+ def initialize(args)
37
+ super(args)
38
+ @dic = otan_alphabet_encode()
39
+ @encode = convert(args)
40
+ @translate = @encode.join(' ')
41
+ @yell = @translate.upcase
42
+ end
43
+
44
+ def to_json
45
+ {
46
+ 'args' => args,
47
+ 'encode' => @encode,
48
+ 'translate' => @translate,
49
+ 'yell' => @yell
50
+ }.to_json
51
+ end
52
+
53
+ private
54
+
55
+ def convert(input)
56
+ input = input.join(' ') if input.is_a?(Array)
57
+ characters = sanitize(input).downcase.chars
58
+ res = characters.map {|char| @dic[char]}.compact
59
+ uniq_separator(res)
60
+ end
61
+
62
+ def uniq_separator(input)
63
+ bucket = []
64
+ input.each do |c|
65
+ bucket << c unless bucket.last == '-' && c == '-'
66
+ end
67
+ bucket
68
+ end
69
+
70
+ end # End of class Encoder
71
+
72
+ class Decoder < Base
73
+
74
+ attr_accessor :decode
75
+
76
+ def initialize(args)
77
+ super(args)
78
+ @dic = otan_alphabet_decode()
79
+ @decode = convert(args)
80
+ @translate = @decode.join()
81
+ @yell = @translate.upcase
82
+ end
83
+
84
+ def to_json
85
+ {
86
+ 'args' => args,
87
+ 'decode' => @decode,
88
+ 'translate' => @translate,
89
+ 'yell' => @yell
90
+ }.to_json
91
+ end
92
+
93
+ private
94
+
95
+ def convert(args)
96
+ words = []
97
+ args = [args] if args.is_a?(String)
98
+ args.each do |el|
99
+ word = el.split(' ')
100
+ word.each {|ok| words << ok}
101
+ end
102
+ words.map {|word| @dic[word]}
103
+ end
104
+
105
+ end # End of class Decoder
106
+
107
+ end # End of module NATOPhone
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module NATOPhone
2
+ VERSION = "0.0.1"
3
+ end
data/spec/helpers.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'stringio'
2
+
3
+ def capture_stdout(&blk)
4
+ old = $stdout
5
+ $stdout = fake = StringIO.new
6
+ blk.call
7
+ fake.string
8
+ ensure
9
+ $stdout = old
10
+ end
11
+
12
+ def capture_stderr(&blk)
13
+ old = $stderr
14
+ $stderr = fake = StringIO.new
15
+ blk.call
16
+ fake.string
17
+ ensure
18
+ $stderr = old
19
+ end
@@ -0,0 +1,17 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require_relative '../lib/version'
5
+ require_relative '../lib/app'
6
+
7
+ RSpec.configure do |config|
8
+ # config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ # Run specs in random order to surface order dependencies. If you find an
12
+ # order dependency and want to debug it, you can fix the order by providing
13
+ # the seed, which is printed after each run.
14
+ # --seed 1234
15
+ config.order = 'random'
16
+ #config.include FakeFS::SpecHelpers, fakefs: true
17
+ end
@@ -0,0 +1,55 @@
1
+ require_relative 'spec_helper'
2
+ require_relative 'helpers'
3
+
4
+ describe NATOPhone::Encoder do
5
+
6
+ let(:enc) { NATOPhone::Encoder.new('Hello World.') }
7
+
8
+ describe "#args" do
9
+
10
+ it "shows args" do
11
+ expect(enc.args).to eq 'Hello World.'
12
+ end
13
+
14
+ it "shows translation" do
15
+ expect(enc.translate).to eq 'hotel echo lima lima oscar - whiskey oscar romeo lima delta stop'
16
+ end
17
+
18
+ it "shows encoded result" do
19
+ expect(enc.encode).to eq ["hotel", "echo", "lima", "lima", "oscar", "-", "whiskey", "oscar", "romeo", "lima", "delta", "stop"]
20
+ end
21
+
22
+ it "shows the yell string" do
23
+ expect(enc.yell).to eq 'HOTEL ECHO LIMA LIMA OSCAR - WHISKEY OSCAR ROMEO LIMA DELTA STOP'
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
30
+ describe NATOPhone::Decoder do
31
+
32
+ let(:dec) { NATOPhone::Decoder.new('hotel echo lima lima oscar - whiskey oscar romeo lima delta stop') }
33
+
34
+ describe "#args" do
35
+
36
+ it "shows args" do
37
+ expect(dec.args).to eq 'hotel echo lima lima oscar - whiskey oscar romeo lima delta stop'
38
+ end
39
+
40
+ it "shows translation" do
41
+ expect(dec.translate).to eq 'hello world.'
42
+ end
43
+
44
+ it "shows decoded result" do
45
+ expect(dec.decode).to eq ["h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d", "."]
46
+ end
47
+
48
+ it "shows the yell string" do
49
+ expect(dec.yell).to eq 'HELLO WORLD.'
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: natophone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric Dejonckheere
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.18'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.18'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rb-fsevent
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Simple tool to encode/decode NATO alphabet. Use as a CLI, or as a library
112
+ for your apps.
113
+ email:
114
+ - eric@aya.io
115
+ executables:
116
+ - natophone
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".coveralls.yml"
121
+ - ".gitignore"
122
+ - ".rspec"
123
+ - ".travis.yml"
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - NATOPhone.gemspec
127
+ - README.md
128
+ - Rakefile
129
+ - bin/natophone
130
+ - lib/app.rb
131
+ - lib/version.rb
132
+ - spec/helpers.rb
133
+ - spec/spec_helper.rb
134
+ - spec/spec_natophone.rb
135
+ homepage: https://github.com/ericdke/NATOPhone
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.4.1
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Simple tool to encode/decode NATO alphabet.
159
+ test_files:
160
+ - spec/helpers.rb
161
+ - spec/spec_helper.rb
162
+ - spec/spec_natophone.rb