natophone 0.0.2 → 0.0.3

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: a8693ad33322d311963546584e9635a68ba9b96d
4
- data.tar.gz: 8ccee5d5594de21dda8499f13c3e458665a0e5a1
3
+ metadata.gz: c22b9ae46a28af9e9a4cdfc480b3d0494bca20c3
4
+ data.tar.gz: 169d1119299ce35c9bf6995f3ea4293f21ac2f4a
5
5
  SHA512:
6
- metadata.gz: 7bf488683604a5acfa65e8c491eb05f50e3e4cc134bd0f8e225b1ba1ba7e888dabbd0eb47705f15e0ef6712f718417e6945f98bf9c5a977977d7ba341c5236fb
7
- data.tar.gz: 704c52b58d500fdb355b0bad165691f2d7cac12c591375f09483bc7356f6c21476d2c533a32b8bfaadba283349c32568f137201b0f9deb6b50fbc8ce7059f455
6
+ metadata.gz: aee62cce368e20f3ddb50ea72638ab8d1daa2d3c4ef76a25dfb31801259cf7a2d7ff04775e3a8b6639824c90c9656c6dee1d990343d0b46b5eae02cb9d97d7c7
7
+ data.tar.gz: 78efa1aa284404573692b281d514a247f9f324d22dfb2b7fcd138b906227848af6d077bff2c515f8502e1dbabcb68e55d9a7dfc05f3bdf56ef487e55f05f378e
@@ -1,3 +1,8 @@
1
+ # 0.0.3
2
+ - Map shortcuts to commands
3
+ - Check input type
4
+ - More tests
5
+
1
6
  # 0.0.2 2014-09-07
2
7
  - Fixes
3
8
  - Tests
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ ![travis](https://travis-ci.org/ericdke/NATOPhone.svg?branch=master)
2
+
3
+ [![Coverage Status](https://img.shields.io/coveralls/ericdke/NATOPhone.svg)](https://coveralls.io/r/ericdke/NATOPhone?branch=master)
4
+
1
5
  # NATOPhone
2
6
 
3
7
  Simple tool to encode/decode [NATO alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet).
@@ -6,7 +10,9 @@ Simple tool to encode/decode [NATO alphabet](https://en.wikipedia.org/wiki/NATO_
6
10
 
7
11
  ### CLI
8
12
 
9
- $ gem install natophone
13
+ ```raw
14
+ gem install natophone
15
+ ```
10
16
 
11
17
  ### Library
12
18
 
@@ -18,23 +24,24 @@ gem 'natophone'
18
24
 
19
25
  And then execute:
20
26
 
21
- $ bundle
27
+ `bundle`
22
28
 
23
29
  ## Usage
24
30
 
25
31
  ### CLI
26
32
 
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
33
+ ```raw
34
+ natophone encode Hello world.
35
+ natophone -E Hello world.
36
+ natophone -E 'Hello world.' 'Goodbye!'
37
+ natophone -E --yell Hello world.
38
+ natophone -E --json Hello world.
39
+ natophone decode hotel echo lima lima oscar - whiskey oscar romeo lima delta stop
40
+ natophone -D hotel echo lima lima oscar - whiskey oscar romeo lima delta stop
41
+ natophone -D 'hotel echo lima lima oscar' 'whiskey oscar romeo lima delta stop'
42
+ natophone -D --yell hotel echo lima lima oscar
43
+ natophone -D --json hotel echo lima lima oscar
44
+ ```
38
45
 
39
46
  ### Library
40
47
 
data/lib/app.rb CHANGED
@@ -21,9 +21,7 @@ module NATOPhone
21
21
 
22
22
  def otan_alphabet_decode
23
23
  otan = otan_alphabet_encode.invert
24
- otan.merge!({
25
- "point" => "."
26
- })
24
+ otan.merge!({"point" => "."})
27
25
  end
28
26
 
29
27
  def sanitize(string)
@@ -53,15 +51,33 @@ module NATOPhone
53
51
  }.to_json
54
52
  end
55
53
 
54
+ def to_s
55
+ @translate
56
+ end
57
+
58
+ def to_a
59
+ @encode
60
+ end
61
+
56
62
  private
57
63
 
58
64
  def convert(input)
59
- input = input.join(' ') if input.is_a?(Array)
65
+ input = check_input(input)
60
66
  characters = sanitize(input).downcase.chars
61
67
  res = characters.map {|char| @dic[char]}.compact
62
68
  uniq_separator(res)
63
69
  end
64
70
 
71
+ def check_input(input)
72
+ if input.is_a?(String)
73
+ return input
74
+ elsif input.is_a?(Array)
75
+ return input.join(' ')
76
+ else
77
+ raise TypeError, "Error: Encoder accepts only Strings or Arrays."
78
+ end
79
+ end
80
+
65
81
  def uniq_separator(input)
66
82
  bucket = []
67
83
  input.each do |c|
@@ -93,22 +109,39 @@ module NATOPhone
93
109
  }.to_json
94
110
  end
95
111
 
112
+ def to_s
113
+ @translate
114
+ end
115
+
116
+ def to_a
117
+ @decode
118
+ end
119
+
96
120
  private
97
121
 
98
122
  def convert(args)
123
+ words = if args.is_a?(String)
124
+ convert_string(args)
125
+ elsif args.is_a?(Array)
126
+ convert_array(args)
127
+ else
128
+ raise TypeError, "Error: Decoder accepts only Strings or Arrays."
129
+ end
130
+ words.map {|word| @dic[word]}
131
+ end
132
+
133
+ def convert_string args
134
+ args.split(' ').map {|word| word}
135
+ end
136
+
137
+ def convert_array args
99
138
  words = []
100
- if args.is_a?(String)
101
- args.split(' ').each do |word|
139
+ args.each do |string|
140
+ string.split(' ').each do |word|
102
141
  words << word
103
142
  end
104
- else
105
- args.each do |string|
106
- string.split(' ').each do |word|
107
- words << word
108
- end
109
- end
110
143
  end
111
- words.map {|word| @dic[word]}
144
+ return words
112
145
  end
113
146
 
114
147
  end # End of class Decoder
data/lib/cli.rb CHANGED
@@ -7,6 +7,7 @@ module NATOPhone
7
7
  class NATOPhoneCLI < Thor
8
8
 
9
9
  desc "encode WORD(S)", "Encode to NATO alphabet"
10
+ map "-E" => "encode"
10
11
  option :yell, aliases: '-Y', type: :boolean, desc: "Option to YELL the translation"
11
12
  option :json, aliases: '-J', type: :boolean, desc: "Option to export the translation in JSON"
12
13
  def encode(*args)
@@ -16,11 +17,12 @@ module NATOPhone
16
17
  elsif options[:json]
17
18
  puts enc.to_json
18
19
  else
19
- puts "\n#{enc.translate}\n\n"
20
+ puts "\n#{enc}\n\n"
20
21
  end
21
22
  end
22
23
 
23
24
  desc "decode NATO", "Decode from NATO alphabet"
25
+ map "-D" => "decode"
24
26
  option :yell, aliases: '-Y', type: :boolean, desc: "Option to YELL the translation"
25
27
  option :json, aliases: '-J', type: :boolean, desc: "Option to export the translation in JSON"
26
28
  def decode(*args)
@@ -30,7 +32,7 @@ module NATOPhone
30
32
  elsif options[:json]
31
33
  puts dec.to_json
32
34
  else
33
- puts "\n#{dec.translate}\n\n"
35
+ puts "\n#{dec}\n\n"
34
36
  end
35
37
  end
36
38
 
@@ -1,3 +1,3 @@
1
1
  module NATOPhone
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -7,11 +7,12 @@ describe NATOPhone::Encoder do
7
7
  let(:enc2) { NATOPhone::Encoder.new(['1.0 Hello World.']) }
8
8
 
9
9
  describe "#args" do
10
+ str = '1.0 Hello World.'
10
11
  it "shows args" do
11
- expect(enc.args).to eq '1.0 Hello World.'
12
+ expect(enc.args).to eq str
12
13
  end
13
14
  it "shows args" do
14
- expect(enc2.args).to eq ["1.0 Hello World."]
15
+ expect(enc2.args).to eq [str]
15
16
  end
16
17
  end
17
18
 
@@ -21,14 +22,17 @@ describe NATOPhone::Encoder do
21
22
  expect(enc.translate).to eq str
22
23
  end
23
24
  it "shows translation" do
24
- expect(enc2.translate).to eq str
25
+ expect(enc2.to_s).to eq str
26
+ end
27
+ it "shows translation" do
28
+ expect(NATOPhone::Encoder.new('uniq spaces').to_s).to eq 'uniform november india quebec - sierra papa alpha charlie echo sierra'
25
29
  end
26
30
  end
27
31
 
28
32
  describe "#encode" do
29
33
  arr = ["one", "stop", "zero", "-", "hotel", "echo", "lima", "lima", "oscar", "-", "whiskey", "oscar", "romeo", "lima", "delta", "stop"]
30
34
  it "shows encoded result" do
31
- expect(enc.encode).to eq arr
35
+ expect(enc.to_a).to eq arr
32
36
  end
33
37
  it "shows encoded result" do
34
38
  expect(enc2.encode).to eq arr
@@ -46,19 +50,29 @@ describe NATOPhone::Encoder do
46
50
  end
47
51
 
48
52
  describe "#to_json" do
53
+ arg = '1.0 Hello World.'
54
+ trans = 'one stop zero - hotel echo lima lima oscar - whiskey oscar romeo lima delta stop'
55
+ deco = ["one", "stop", "zero", "-", "hotel", "echo", "lima", "lima", "oscar", "-", "whiskey", "oscar", "romeo", "lima", "delta", "stop"]
56
+ ye = 'ONE STOP ZERO - HOTEL ECHO LIMA LIMA OSCAR - WHISKEY OSCAR ROMEO LIMA DELTA STOP'
49
57
  it "outputs json" do
50
58
  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'
59
+ expect(j['args']).to eq arg
60
+ expect(j['translate']).to eq trans
61
+ expect(j['encode']).to eq deco
62
+ expect(j['yell']).to eq ye
55
63
  end
56
64
  it "outputs json" do
57
65
  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'
66
+ expect(j['args']).to eq [arg]
67
+ expect(j['translate']).to eq trans
68
+ expect(j['encode']).to eq deco
69
+ expect(j['yell']).to eq ye
70
+ end
71
+ end
72
+
73
+ describe "type error" do
74
+ it "raises a type error" do
75
+ expect(lambda {NATOPhone::Encoder.new({'test' => 'Run, you fools!'})}).to raise_error(TypeError)
62
76
  end
63
77
  end
64
78
 
@@ -82,10 +96,10 @@ describe NATOPhone::Decoder do
82
96
  describe "#translate" do
83
97
  str = '1.0 hello world.'
84
98
  it "shows translation" do
85
- expect(dec.translate).to eq str
99
+ expect(dec.to_s).to eq str
86
100
  end
87
101
  it "shows translation" do
88
- expect(dec2.translate).to eq str
102
+ expect(dec2.to_s).to eq str
89
103
  end
90
104
  end
91
105
 
@@ -130,5 +144,11 @@ describe NATOPhone::Decoder do
130
144
  end
131
145
  end
132
146
 
147
+ describe "type error" do
148
+ it "raises a type error" do
149
+ expect(lambda {NATOPhone::Decoder.new({'test' => 'Run, you fools!'})}).to raise_error(TypeError)
150
+ end
151
+ end
152
+
133
153
  end
134
154
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natophone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dejonckheere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-06 00:00:00.000000000 Z
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor