natophone 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc66af7ce5d5d06b5f361de80a33dabf020ee0e1
4
- data.tar.gz: 791a88cbb58dcac56fc8cec7b4cdecc30712576b
3
+ metadata.gz: a8693ad33322d311963546584e9635a68ba9b96d
4
+ data.tar.gz: 8ccee5d5594de21dda8499f13c3e458665a0e5a1
5
5
  SHA512:
6
- metadata.gz: 6d3b3b03deb38d7ae7e97037821fae5689707327e51670dc5cbcb7e437ae39f21a3355ea5f5965478f9849a1f2cb181e7d46c3e0e12c6418947d1eae609c3880
7
- data.tar.gz: abbc572696c83f6de710c0ea56cf379be711faa593ad9c04183382d8dee30d9764e3cc508df6d4de0d95e4e97505880a2d0f19026a0afdbbb9a17cd889927ebb
6
+ metadata.gz: 7bf488683604a5acfa65e8c491eb05f50e3e4cc134bd0f8e225b1ba1ba7e888dabbd0eb47705f15e0ef6712f718417e6945f98bf9c5a977977d7ba341c5236fb
7
+ data.tar.gz: 704c52b58d500fdb355b0bad165691f2d7cac12c591375f09483bc7356f6c21476d2c533a32b8bfaadba283349c32568f137201b0f9deb6b50fbc8ce7059f455
@@ -6,8 +6,9 @@ rvm:
6
6
  - "2.1.1"
7
7
  - "2.1.0"
8
8
  - "2.0.0"
9
+ - "1.9.3"
9
10
 
10
- script: 'rspec spec/spec_natophone.rb'
11
+ script: 'bundle exec rake spec'
11
12
 
12
13
  branches:
13
14
  only:
@@ -0,0 +1,7 @@
1
+ # 0.0.2 2014-09-07
2
+ - Fixes
3
+ - Tests
4
+ - New app structure
5
+
6
+ # 0.0.1 2014-09-07
7
+ - Encode, Decode, CLI
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require_relative 'lib/version'
4
+ require 'version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "natophone"
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "thor", "~> 0.18"
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 2.14"
27
27
  spec.add_development_dependency "rb-fsevent", "~> 0.9"
data/README.md CHANGED
@@ -39,11 +39,15 @@ And then execute:
39
39
  ### Library
40
40
 
41
41
  ```ruby
42
- enc = NATOPhone::Encoder.new(args)
43
- puts enc.inspect
42
+ require 'natophone'
44
43
  ```
45
44
 
46
45
  ```ruby
47
- dec = NATOPhone::Decoder.new(args)
48
- puts dec.inspect
46
+ enc_by_string = NATOPhone::Encoder.new('hello world')
47
+ enc_by_array = NATOPhone::Encoder.new(['hello', 'world'])
48
+ ```
49
+
50
+ ```ruby
51
+ dec_by_string = NATOPhone::Decoder.new('hotel echo lima lima oscar - whiskey oscar romeo lima delta')
52
+ dec_by_array = NATOPhone::Decoder.new(%w{hotel echo lima lima oscar - whiskey oscar romeo lima delta})
49
53
  ```
@@ -3,39 +3,6 @@
3
3
 
4
4
  require_relative "../lib/version"
5
5
  require_relative '../lib/app'
6
+ require_relative "../lib/cli"
6
7
 
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)
8
+ NATOPhone::NATOPhoneCLI.start(ARGV)
data/lib/app.rb CHANGED
@@ -20,7 +20,10 @@ module NATOPhone
20
20
  end
21
21
 
22
22
  def otan_alphabet_decode
23
- otan_alphabet_encode.invert
23
+ otan = otan_alphabet_encode.invert
24
+ otan.merge!({
25
+ "point" => "."
26
+ })
24
27
  end
25
28
 
26
29
  def sanitize(string)
@@ -43,7 +46,7 @@ module NATOPhone
43
46
 
44
47
  def to_json
45
48
  {
46
- 'args' => args,
49
+ 'args' => @args,
47
50
  'encode' => @encode,
48
51
  'translate' => @translate,
49
52
  'yell' => @yell
@@ -83,7 +86,7 @@ module NATOPhone
83
86
 
84
87
  def to_json
85
88
  {
86
- 'args' => args,
89
+ 'args' => @args,
87
90
  'decode' => @decode,
88
91
  'translate' => @translate,
89
92
  'yell' => @yell
@@ -94,10 +97,16 @@ module NATOPhone
94
97
 
95
98
  def convert(args)
96
99
  words = []
97
- args = [args] if args.is_a?(String)
98
- args.each do |el|
99
- word = el.split(' ')
100
- word.each {|ok| words << ok}
100
+ if args.is_a?(String)
101
+ args.split(' ').each do |word|
102
+ words << word
103
+ end
104
+ else
105
+ args.each do |string|
106
+ string.split(' ').each do |word|
107
+ words << word
108
+ end
109
+ end
101
110
  end
102
111
  words.map {|word| @dic[word]}
103
112
  end
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: UTF-8
3
+
4
+ require "thor"
5
+
6
+ module NATOPhone
7
+ class NATOPhoneCLI < Thor
8
+
9
+ desc "encode WORD(S)", "Encode to NATO alphabet"
10
+ option :yell, aliases: '-Y', type: :boolean, desc: "Option to YELL the translation"
11
+ option :json, aliases: '-J', type: :boolean, desc: "Option to export the translation in JSON"
12
+ def encode(*args)
13
+ enc = NATOPhone::Encoder.new(args)
14
+ if options[:yell]
15
+ puts "\n#{enc.yell}\n\n"
16
+ elsif options[:json]
17
+ puts enc.to_json
18
+ else
19
+ puts "\n#{enc.translate}\n\n"
20
+ end
21
+ end
22
+
23
+ desc "decode NATO", "Decode from NATO alphabet"
24
+ option :yell, aliases: '-Y', type: :boolean, desc: "Option to YELL the translation"
25
+ option :json, aliases: '-J', type: :boolean, desc: "Option to export the translation in JSON"
26
+ def decode(*args)
27
+ dec = NATOPhone::Decoder.new(args)
28
+ if options[:yell]
29
+ puts "\n#{dec.yell}\n\n"
30
+ elsif options[:json]
31
+ puts dec.to_json
32
+ else
33
+ puts "\n#{dec.translate}\n\n"
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module NATOPhone
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,42 @@
1
+ require_relative 'spec_helper'
2
+ require_relative 'helpers'
3
+
4
+ describe NATOPhone::NATOPhoneCLI do
5
+
6
+ let(:cli) {NATOPhone::NATOPhoneCLI}
7
+
8
+ describe "#encode" do
9
+ it "encodes" do
10
+ printed = capture_stdout do
11
+ test = lambda {cli.start(['encode', 'hello world'])}
12
+ test.call
13
+ end
14
+ expect(printed).to eq "\nhotel echo lima lima oscar - whiskey oscar romeo lima delta\n\n"
15
+ end
16
+ it "encodes" do
17
+ printed = capture_stdout do
18
+ test = lambda {cli.start(['encode', 'hello', 'world'])}
19
+ test.call
20
+ end
21
+ expect(printed).to eq "\nhotel echo lima lima oscar - whiskey oscar romeo lima delta\n\n"
22
+ end
23
+ end
24
+
25
+ describe "#decode" do
26
+ it "decodes" do
27
+ printed = capture_stdout do
28
+ test = lambda {cli.start(['decode', 'hotel echo lima lima oscar - whiskey oscar romeo lima delta'])}
29
+ test.call
30
+ end
31
+ expect(printed).to eq "\nhello world\n\n"
32
+ end
33
+ it "decodes" do
34
+ printed = capture_stdout do
35
+ test = lambda {cli.start(['decode', 'hotel', 'echo'])}
36
+ test.call
37
+ end
38
+ expect(printed).to eq "\nhe\n\n"
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,134 @@
1
+ require_relative 'spec_helper'
2
+ require_relative 'helpers'
3
+
4
+ describe NATOPhone::Encoder do
5
+
6
+ let(:enc) { NATOPhone::Encoder.new('1.0 Hello World.') }
7
+ let(:enc2) { NATOPhone::Encoder.new(['1.0 Hello World.']) }
8
+
9
+ describe "#args" do
10
+ it "shows args" do
11
+ expect(enc.args).to eq '1.0 Hello World.'
12
+ end
13
+ it "shows args" do
14
+ expect(enc2.args).to eq ["1.0 Hello World."]
15
+ end
16
+ end
17
+
18
+ describe "#translate" do
19
+ str = 'one stop zero - hotel echo lima lima oscar - whiskey oscar romeo lima delta stop'
20
+ it "shows translation" do
21
+ expect(enc.translate).to eq str
22
+ end
23
+ it "shows translation" do
24
+ expect(enc2.translate).to eq str
25
+ end
26
+ end
27
+
28
+ describe "#encode" do
29
+ arr = ["one", "stop", "zero", "-", "hotel", "echo", "lima", "lima", "oscar", "-", "whiskey", "oscar", "romeo", "lima", "delta", "stop"]
30
+ it "shows encoded result" do
31
+ expect(enc.encode).to eq arr
32
+ end
33
+ it "shows encoded result" do
34
+ expect(enc2.encode).to eq arr
35
+ end
36
+ end
37
+
38
+ describe "#yell" do
39
+ str = 'ONE STOP ZERO - HOTEL ECHO LIMA LIMA OSCAR - WHISKEY OSCAR ROMEO LIMA DELTA STOP'
40
+ it "shows the yell string" do
41
+ expect(enc.yell).to eq str
42
+ end
43
+ it "shows the yell string" do
44
+ expect(enc2.yell).to eq str
45
+ end
46
+ end
47
+
48
+ describe "#to_json" do
49
+ it "outputs json" do
50
+ j = JSON.parse(enc.to_json)
51
+ expect(j['args']).to eq '1.0 Hello World.'
52
+ expect(j['translate']).to eq 'one stop zero - hotel echo lima lima oscar - whiskey oscar romeo lima delta stop'
53
+ expect(j['encode']).to eq ["one", "stop", "zero", "-", "hotel", "echo", "lima", "lima", "oscar", "-", "whiskey", "oscar", "romeo", "lima", "delta", "stop"]
54
+ expect(j['yell']).to eq 'ONE STOP ZERO - HOTEL ECHO LIMA LIMA OSCAR - WHISKEY OSCAR ROMEO LIMA DELTA STOP'
55
+ end
56
+ it "outputs json" do
57
+ j = JSON.parse(enc2.to_json)
58
+ expect(j['args']).to eq ['1.0 Hello World.']
59
+ expect(j['translate']).to eq 'one stop zero - hotel echo lima lima oscar - whiskey oscar romeo lima delta stop'
60
+ expect(j['encode']).to eq ["one", "stop", "zero", "-", "hotel", "echo", "lima", "lima", "oscar", "-", "whiskey", "oscar", "romeo", "lima", "delta", "stop"]
61
+ expect(j['yell']).to eq 'ONE STOP ZERO - HOTEL ECHO LIMA LIMA OSCAR - WHISKEY OSCAR ROMEO LIMA DELTA STOP'
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ describe NATOPhone::Decoder do
68
+
69
+ let(:dec) { NATOPhone::Decoder.new('one point zero - hotel echo lima lima oscar - whiskey oscar romeo lima delta stop') }
70
+ let(:dec2) { NATOPhone::Decoder.new(['one point zero - hotel echo lima lima oscar - whiskey oscar romeo lima delta stop']) }
71
+
72
+ describe "#args" do
73
+ str = 'one point zero - hotel echo lima lima oscar - whiskey oscar romeo lima delta stop'
74
+ it "shows args" do
75
+ expect(dec.args).to eq str
76
+ end
77
+ it "shows args" do
78
+ expect(dec2.args).to eq [str]
79
+ end
80
+ end
81
+
82
+ describe "#translate" do
83
+ str = '1.0 hello world.'
84
+ it "shows translation" do
85
+ expect(dec.translate).to eq str
86
+ end
87
+ it "shows translation" do
88
+ expect(dec2.translate).to eq str
89
+ end
90
+ end
91
+
92
+ describe "#decode" do
93
+ arr = ["1", ".", "0", " ", "h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d", "."]
94
+ it "shows decoded result" do
95
+ expect(dec.decode).to eq arr
96
+ end
97
+ it "shows decoded result" do
98
+ expect(dec2.decode).to eq arr
99
+ end
100
+ end
101
+
102
+ describe "#yell" do
103
+ str = '1.0 HELLO WORLD.'
104
+ it "shows the yell string" do
105
+ expect(dec.yell).to eq str
106
+ end
107
+ it "shows the yell string" do
108
+ expect(dec2.yell).to eq str
109
+ end
110
+ end
111
+
112
+ describe "#to_json" do
113
+ arg = 'one point zero - hotel echo lima lima oscar - whiskey oscar romeo lima delta stop'
114
+ trans = '1.0 hello world.'
115
+ deco = ["1", ".", "0", " ", "h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d", "."]
116
+ ye = '1.0 HELLO WORLD.'
117
+ it "outputs json" do
118
+ j = JSON.parse(dec.to_json)
119
+ expect(j['args']).to eq arg
120
+ expect(j['translate']).to eq trans
121
+ expect(j['decode']).to eq deco
122
+ expect(j['yell']).to eq ye
123
+ end
124
+ it "outputs json" do
125
+ j = JSON.parse(dec2.to_json)
126
+ expect(j['args']).to eq [arg]
127
+ expect(j['translate']).to eq trans
128
+ expect(j['decode']).to eq deco
129
+ expect(j['yell']).to eq ye
130
+ end
131
+ end
132
+
133
+ end
134
+
@@ -3,9 +3,10 @@ Coveralls.wear!
3
3
 
4
4
  require_relative '../lib/version'
5
5
  require_relative '../lib/app'
6
+ require_relative '../lib/cli'
6
7
 
7
8
  RSpec.configure do |config|
8
- # config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
10
  config.run_all_when_everything_filtered = true
10
11
  config.filter_run :focus
11
12
  # Run specs in random order to surface order dependencies. If you find an
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natophone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dejonckheere
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.7'
33
+ version: '1.6'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.7'
40
+ version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -121,6 +121,7 @@ files:
121
121
  - ".gitignore"
122
122
  - ".rspec"
123
123
  - ".travis.yml"
124
+ - CHANGELOG.md
124
125
  - Gemfile
125
126
  - LICENSE.txt
126
127
  - NATOPhone.gemspec
@@ -128,10 +129,12 @@ files:
128
129
  - Rakefile
129
130
  - bin/natophone
130
131
  - lib/app.rb
132
+ - lib/cli.rb
131
133
  - lib/version.rb
134
+ - spec/cli_spec.rb
132
135
  - spec/helpers.rb
136
+ - spec/natophone_spec.rb
133
137
  - spec/spec_helper.rb
134
- - spec/spec_natophone.rb
135
138
  homepage: https://github.com/ericdke/NATOPhone
136
139
  licenses:
137
140
  - MIT
@@ -157,6 +160,7 @@ signing_key:
157
160
  specification_version: 4
158
161
  summary: Simple tool to encode/decode NATO alphabet.
159
162
  test_files:
163
+ - spec/cli_spec.rb
160
164
  - spec/helpers.rb
165
+ - spec/natophone_spec.rb
161
166
  - spec/spec_helper.rb
162
- - spec/spec_natophone.rb
@@ -1,55 +0,0 @@
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
-