vail 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +27 -7
- data/VERSION +1 -1
- data/bin/vail +11 -4
- data/config/default.yaml +2 -0
- data/lib/vail.rb +1 -1
- data/lib/vail/command/pause.rb +12 -0
- data/lib/vail/command/sound.rb +14 -0
- data/lib/vail/generator.rb +38 -14
- data/spec/vail/command/pause_spec.rb +10 -0
- data/spec/vail/command/sound_spec.rb +10 -0
- data/spec/vail/generator_spec.rb +46 -10
- data/vail.gemspec +6 -2
- metadata +8 -4
data/README.rdoc
CHANGED
@@ -11,7 +11,14 @@ Due to vail's reliance on beep, prior to installing the vail gem (or running the
|
|
11
11
|
== Customisable Settings
|
12
12
|
|
13
13
|
* duration - this can be set for a dot or a dash and the units are milliseconds
|
14
|
-
* pause - this is the time in milliseconds that vail will pause for before proceeding to the next set of instructions
|
14
|
+
* pause - this is the time in milliseconds that vail will pause for before proceeding to the next set of instructions. A pause can be applied after the following elements:
|
15
|
+
* a dot
|
16
|
+
* a dash
|
17
|
+
* a letter
|
18
|
+
* a group of letters (separated by a space)
|
19
|
+
* a line
|
20
|
+
* a repetition
|
21
|
+
|
15
22
|
* frequency - of the sound generated, in Hz. It is applied to both dots and dashes
|
16
23
|
* repetitions - the number of times the provided string will be repeated
|
17
24
|
|
@@ -21,11 +28,13 @@ The vail executable can be run to output Morse code from the commandline. Execut
|
|
21
28
|
|
22
29
|
vail
|
23
30
|
|
24
|
-
You will be prompted to enter the text and you
|
25
|
-
|
26
|
-
There are currently two commandline options available. These allow you to export the current default settings for the gem and import settings from a specified file. A brief description of these two options can also be found by running:
|
31
|
+
You will be prompted to enter the text and you should be rewarded with a sequence of beeps representing the dots and dashes for the various letters. To exit, simply hit Ctrl-C.
|
27
32
|
|
28
|
-
|
33
|
+
The following options can be passed when running the executable from the commandline:
|
34
|
+
* --export, -e : Export settings
|
35
|
+
* --import, -i : Import settings
|
36
|
+
* --text, -t : Load a file containing text to be converted to Morse
|
37
|
+
* --help, -h : Help
|
29
38
|
|
30
39
|
=== Export settings
|
31
40
|
|
@@ -41,6 +50,14 @@ Settings may be imported to override the default settings for the gem. An export
|
|
41
50
|
|
42
51
|
vail -i /path/to/custom/settings
|
43
52
|
|
53
|
+
=== Load text from file
|
54
|
+
|
55
|
+
Text can be loaded from a file and then converted into Morse. vail will treat each line as a seperate set of instructions. Therefore if repeptitions have been applied each line will be repeated for the given number of repetitions before proceeding on to the next line.
|
56
|
+
|
57
|
+
vail -t /path/to/input/file
|
58
|
+
|
59
|
+
Vail will wait the number of milliseconds provided for in the line pause before proceeding to the next line.
|
60
|
+
|
44
61
|
== Usage - in Ruby code
|
45
62
|
|
46
63
|
To use the vail module in Ruby code is reasonably simple - just bear in mind that it is subject to the same restrictions as the executable (linux only, requires the beep utility):
|
@@ -52,7 +69,7 @@ To use the vail module in Ruby code is reasonably simple - just bear in mind tha
|
|
52
69
|
|
53
70
|
=== Providing custom settings
|
54
71
|
|
55
|
-
The default settings can be overridden by passing a hash of custom settings - in the code below, only the repetitions
|
72
|
+
The default settings can be overridden by passing a hash of custom settings - in the code below, only the repetitions element is optional. Excluding any of the other options will result in Vail puking horribly :)
|
56
73
|
|
57
74
|
@settings = {
|
58
75
|
"dot" => { "duration" => 100, "pause" => 200 },
|
@@ -60,11 +77,14 @@ The default settings can be overridden by passing a hash of custom settings - in
|
|
60
77
|
"frequency" => 250,
|
61
78
|
"letter" => { "pause" => 100 },
|
62
79
|
"group" => { "pause" => 200 },
|
63
|
-
"
|
80
|
+
"line" => { "pause" => 1200 },
|
81
|
+
"repetitions" => { "pause" => 800, "repeat" => 2 }
|
64
82
|
}
|
65
83
|
|
66
84
|
Vail::Generator.new(@settings).to_morse("T")
|
67
85
|
|
86
|
+
If the value of @settings["repetitions"]["repeat"] is 0, vail will run through the text provided once. In addition, to allow backwards compatibility, vail will allow the repetitions element to be an integer. In this case, due to poor reasoning by the developer :), the number of repetitions is the total number of times it will run (repetitions => 1 means it will run once) - so, far better to go with the new settings format if you can.
|
87
|
+
|
68
88
|
== Contributing to vail
|
69
89
|
|
70
90
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/vail
CHANGED
@@ -12,6 +12,7 @@ end
|
|
12
12
|
opts = Trollop::options do
|
13
13
|
opt :export, "Output current default settings"
|
14
14
|
opt :import, "Run with settings in provided YAML file", :type => String
|
15
|
+
opt :text, "File containing text for conversion to morse", :type => String
|
15
16
|
end
|
16
17
|
|
17
18
|
if opts[:export]
|
@@ -21,9 +22,15 @@ else
|
|
21
22
|
|
22
23
|
settings = opts[:import] ? YAML::load(IO.read(opts[:import])) : {}
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
generator = Vail::Generator.new(settings)
|
26
|
+
|
27
|
+
if opts[:text]
|
28
|
+
generator.to_morse(IO.read(opts[:text]))
|
29
|
+
else
|
30
|
+
while true
|
31
|
+
puts "Please enter the text for conversion:"
|
32
|
+
text = gets.strip
|
33
|
+
generator.to_morse(text)
|
34
|
+
end
|
28
35
|
end
|
29
36
|
end
|
data/config/default.yaml
CHANGED
data/lib/vail.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'beep'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
-
['vail/config', 'vail/dot_dash', 'vail/translate', 'vail/generator'].each do |f|
|
4
|
+
['vail/config', 'vail/dot_dash', 'vail/translate', 'vail/generator', 'vail/command/sound', 'vail/command/pause'].each do |f|
|
5
5
|
require File.join(File.dirname(__FILE__), f)
|
6
6
|
end
|
7
7
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Vail
|
2
|
+
module Command
|
3
|
+
class Sound
|
4
|
+
def initialize(morse)
|
5
|
+
@morse = morse
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute(config)
|
9
|
+
Beep::Sound.generate(@morse.map { |dotdash| { :duration => config[dotdash]["duration"], :pause => config[dotdash]["pause"], :frequency => config["frequency"] }})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
data/lib/vail/generator.rb
CHANGED
@@ -9,13 +9,21 @@ module Vail
|
|
9
9
|
Dash => { "duration" => config["dash"]["duration"], "pause" => config["dash"]["pause"]}
|
10
10
|
}
|
11
11
|
)
|
12
|
-
@config["repetitions"] ||= 1
|
13
|
-
end
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
@config.merge! (
|
14
|
+
case @config["repetitions"]
|
15
|
+
when Hash
|
16
|
+
{}
|
17
|
+
when Fixnum
|
18
|
+
{ "repetitions" => { "repeat" => (@config["repetitions"] - 1), "pause" => 800 } }
|
19
|
+
when NilClass
|
20
|
+
{ "repetitions" => { "repeat" => 0, "pause" => 800 } }
|
21
|
+
end
|
22
|
+
)
|
23
|
+
end
|
17
24
|
|
18
|
-
|
25
|
+
def to_morse(text)
|
26
|
+
convert_to_instructions(text).each do |instruction_set|
|
19
27
|
instruction_set.each do |i|
|
20
28
|
execute_instruction(i)
|
21
29
|
end
|
@@ -28,30 +36,46 @@ module Vail
|
|
28
36
|
|
29
37
|
private
|
30
38
|
|
39
|
+
def convert_to_instructions(text)
|
40
|
+
lines = text.split("\n")
|
41
|
+
|
42
|
+
# the last line does not get a line pause - so handle it first
|
43
|
+
|
44
|
+
last_line = repeat(build_instructions(lines.pop))
|
45
|
+
|
46
|
+
lines.inject([]) do |store,line|
|
47
|
+
store + (repeat(build_instructions(line)) << [Command::Pause.new('line')])
|
48
|
+
end + last_line
|
49
|
+
end
|
50
|
+
|
31
51
|
def build_instructions(phrase)
|
32
52
|
instructions = []
|
33
53
|
|
34
54
|
phrase.each_char do |char|
|
35
55
|
if char == " "
|
36
|
-
instructions <<
|
56
|
+
instructions << Command::Pause.new('group')
|
37
57
|
else
|
38
58
|
morse = Translate.to_morse(char)
|
39
|
-
instructions <<
|
40
|
-
|
41
|
-
:instruction => morse.map { |dotdash| { :duration => @config[dotdash]["duration"], :pause => @config[dotdash]["pause"], :frequency => @config["frequency"] }}
|
42
|
-
}
|
43
|
-
instructions << { :command => :sleep, :instruction => @config["letter"]["pause"].to_f/1000.0}
|
59
|
+
instructions << Command::Sound.new(morse)
|
60
|
+
instructions << Command::Pause.new('letter')
|
44
61
|
end
|
45
62
|
end
|
46
63
|
|
47
64
|
instructions
|
48
65
|
end
|
49
66
|
|
67
|
+
def repeat(instructions)
|
68
|
+
# Add a repetition pause for the repeats only
|
69
|
+
(@config["repetitions"]["repeat"]).times.inject([]) do
|
70
|
+
|r,i| r << (instructions +[Command::Pause.new("repetitions")])
|
71
|
+
end << instructions
|
72
|
+
end
|
73
|
+
|
50
74
|
def execute_instruction(instruction)
|
51
|
-
if instruction
|
52
|
-
Beep::Sound.generate(instruction[:instruction])
|
53
|
-
else
|
75
|
+
if instruction.is_a? Hash
|
54
76
|
sleep(instruction[:instruction])
|
77
|
+
else
|
78
|
+
instruction.execute(@config)
|
55
79
|
end
|
56
80
|
end
|
57
81
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Vail::Command::Pause do
|
4
|
+
it "should pause for the number of milliseconds specified in the config for the relevant type of pause" do
|
5
|
+
p = Vail::Command::Pause.new('blah')
|
6
|
+
p.should_receive(:sleep).with(0.50)
|
7
|
+
p.execute({'blah' => { 'pause' => 500 }})
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Vail::Command::Sound do
|
4
|
+
it "should generate sound with the correct settings for a dot or dash" do
|
5
|
+
s = Vail::Command::Sound.new([Vail::Dot, Vail::Dash])
|
6
|
+
Beep::Sound.should_receive(:generate).with([{ :duration => 100, :pause => 200, :frequency => 500 }, { :duration => 300, :pause => 400, :frequency => 500 }])
|
7
|
+
s.execute({ Vail::Dot => { "duration" => 100, "pause" => 200 }, Vail::Dash => { "duration" => 300, "pause" => 400 }, "frequency" => 500 })
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
data/spec/vail/generator_spec.rb
CHANGED
@@ -7,8 +7,10 @@ describe Vail::Generator do
|
|
7
7
|
"dash" => { "duration" => 300, "pause" => 400 },
|
8
8
|
"frequency" => 250,
|
9
9
|
"letter" => { "pause" => 100 },
|
10
|
-
"group" => { "pause" => 200 }
|
10
|
+
"group" => { "pause" => 200 },
|
11
|
+
"line" => { "pause" => 400 }
|
11
12
|
}
|
13
|
+
@mock_pause = double(Vail::Command::Pause)
|
12
14
|
end
|
13
15
|
it "should load default settings upon initialisation if none are provided" do
|
14
16
|
IO.should_receive(:read).with(Vail::ConfigPath).and_return('blah')
|
@@ -41,10 +43,11 @@ describe Vail::Generator do
|
|
41
43
|
|
42
44
|
it "should provide an additional pause after a letter is completed" do
|
43
45
|
Vail::Translate.stub!(:to_morse).and_return([Vail::Dash, Vail::Dash, Vail::Dot])
|
46
|
+
|
44
47
|
Beep::Sound.should_receive(:generate)
|
45
48
|
|
46
49
|
g = Vail::Generator.new(@settings)
|
47
|
-
|
50
|
+
Vail::Command::Pause.any_instance.should_receive(:sleep).with(@settings["letter"]["pause"].to_f/1000.0)
|
48
51
|
g.to_morse("G")
|
49
52
|
end
|
50
53
|
|
@@ -62,11 +65,13 @@ describe Vail::Generator do
|
|
62
65
|
Vail::Translate.stub!(:to_morse).with('G').and_return([Vail::Dash, Vail::Dash, Vail::Dot])
|
63
66
|
Vail::Translate.stub!(:to_morse).with('O').and_return([Vail::Dash, Vail::Dash, Vail::Dash])
|
64
67
|
|
68
|
+
@mock_pause.should_receive(:execute).twice
|
69
|
+
Vail::Command::Pause.should_receive(:new).with('letter').twice.and_return(@mock_pause)
|
70
|
+
|
65
71
|
Beep::Sound.should_receive(:generate).with(sound_parameters_G).ordered
|
66
72
|
Beep::Sound.should_receive(:generate).with(sound_parameters_O).ordered
|
67
73
|
|
68
74
|
g = Vail::Generator.new(@settings)
|
69
|
-
g.should_receive(:sleep).with(@settings["letter"]["pause"].to_f/1000.0).twice
|
70
75
|
g.to_morse("GO")
|
71
76
|
end
|
72
77
|
|
@@ -76,10 +81,11 @@ describe Vail::Generator do
|
|
76
81
|
|
77
82
|
Beep::Sound.stub!(:generate)
|
78
83
|
|
84
|
+
@mock_pause.should_receive(:execute).exactly(5).times
|
85
|
+
Vail::Command::Pause.should_receive(:new).with('letter').exactly(4).times.and_return(@mock_pause)
|
86
|
+
Vail::Command::Pause.should_receive(:new).with('group').and_return(@mock_pause)
|
87
|
+
|
79
88
|
g = Vail::Generator.new(@settings)
|
80
|
-
g.should_receive(:sleep).with(@settings["letter"]["pause"].to_f/1000.0).twice.ordered
|
81
|
-
g.should_receive(:sleep).with(@settings["group"]["pause"].to_f/1000.0).ordered
|
82
|
-
g.should_receive(:sleep).with(@settings["letter"]["pause"].to_f/1000.0).twice.ordered
|
83
89
|
g.to_morse("GO GO")
|
84
90
|
end
|
85
91
|
|
@@ -89,14 +95,44 @@ describe Vail::Generator do
|
|
89
95
|
|
90
96
|
Beep::Sound.stub!(:generate)
|
91
97
|
|
92
|
-
|
93
|
-
|
94
|
-
|
98
|
+
@mock_pause.should_receive(:execute).exactly(8).times
|
99
|
+
|
100
|
+
mock_pause_group = double(Vail::Command::Pause)
|
101
|
+
mock_pause_group.should_receive(:execute).twice
|
102
|
+
|
103
|
+
mock_pause_rep = double(Vail::Command::Pause)
|
104
|
+
mock_pause_rep.should_receive(:execute)
|
105
|
+
|
106
|
+
Vail::Command::Pause.should_receive(:new).with('letter').exactly(4).times.and_return(@mock_pause)
|
107
|
+
Vail::Command::Pause.should_receive(:new).with('group').and_return(mock_pause_group)
|
108
|
+
Vail::Command::Pause.should_receive(:new).with('repetitions').and_return(mock_pause_rep)
|
109
|
+
|
110
|
+
settings = @settings.merge("repetitions" => { 'repeat' => 1, 'pause' => 800 })
|
111
|
+
|
112
|
+
g = Vail::Generator.new(settings)
|
95
113
|
g.to_morse("GO GO")
|
96
114
|
end
|
97
115
|
|
116
|
+
it "should accept a scalar value (old settings format) for the repetitions settings key and set a default repetition pause" do
|
117
|
+
Vail::Generator.new(@settings.merge("repetitions" => 5)).settings.should == @settings.merge({"repetitions" => { "repeat" => 4, "pause" => 800}})
|
118
|
+
end
|
119
|
+
|
98
120
|
it "should be able to return the current settings object including any defaults applied" do
|
99
|
-
Vail::Generator.new(@settings).settings.should == @settings.merge("repetitions" =>
|
121
|
+
Vail::Generator.new(@settings).settings.should == @settings.merge("repetitions" => { "repeat" => 0, "pause" => 800})
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should split input text on newlines and treat each newline as a separate set of instructions with defined pause between each set" do
|
125
|
+
Vail::Translate.should_receive(:to_morse).with("G").twice.and_return([Vail::Dash, Vail::Dash, Vail::Dot])
|
126
|
+
Vail::Translate.should_receive(:to_morse).with('O').twice.and_return([Vail::Dash, Vail::Dash, Vail::Dash])
|
127
|
+
|
128
|
+
Beep::Sound.stub!(:generate)
|
129
|
+
|
130
|
+
@mock_pause.should_receive(:execute).exactly(5).times
|
131
|
+
Vail::Command::Pause.should_receive(:new).with('letter').exactly(4).times.and_return(@mock_pause)
|
132
|
+
Vail::Command::Pause.should_receive(:new).with('line').and_return(@mock_pause)
|
133
|
+
|
134
|
+
g = Vail::Generator.new(@settings)
|
135
|
+
g.to_morse("GO\nGO\n")
|
100
136
|
end
|
101
137
|
end
|
102
138
|
|
data/vail.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{vail}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rory McKinley"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-07-04}
|
13
13
|
s.default_executable = %q{vail}
|
14
14
|
s.description = %q{Vail generates audible morse code. Currently it only works on Linux distros that have the beep utility installed. This is hopefully a temporary limitation}
|
15
15
|
s.email = %q{rorymckinley@gmail.com}
|
@@ -30,11 +30,15 @@ Gem::Specification.new do |s|
|
|
30
30
|
"bin/vail",
|
31
31
|
"config/default.yaml",
|
32
32
|
"lib/vail.rb",
|
33
|
+
"lib/vail/command/pause.rb",
|
34
|
+
"lib/vail/command/sound.rb",
|
33
35
|
"lib/vail/config.rb",
|
34
36
|
"lib/vail/dot_dash.rb",
|
35
37
|
"lib/vail/generator.rb",
|
36
38
|
"lib/vail/translate.rb",
|
37
39
|
"spec/spec_helper.rb",
|
40
|
+
"spec/vail/command/pause_spec.rb",
|
41
|
+
"spec/vail/command/sound_spec.rb",
|
38
42
|
"spec/vail/generator_spec.rb",
|
39
43
|
"spec/vail/translate_spec.rb",
|
40
44
|
"spec/vail_spec.rb",
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 1
|
8
7
|
- 2
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Rory McKinley
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-07-04 00:00:00 +02:00
|
18
18
|
default_executable: vail
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -124,11 +124,15 @@ files:
|
|
124
124
|
- bin/vail
|
125
125
|
- config/default.yaml
|
126
126
|
- lib/vail.rb
|
127
|
+
- lib/vail/command/pause.rb
|
128
|
+
- lib/vail/command/sound.rb
|
127
129
|
- lib/vail/config.rb
|
128
130
|
- lib/vail/dot_dash.rb
|
129
131
|
- lib/vail/generator.rb
|
130
132
|
- lib/vail/translate.rb
|
131
133
|
- spec/spec_helper.rb
|
134
|
+
- spec/vail/command/pause_spec.rb
|
135
|
+
- spec/vail/command/sound_spec.rb
|
132
136
|
- spec/vail/generator_spec.rb
|
133
137
|
- spec/vail/translate_spec.rb
|
134
138
|
- spec/vail_spec.rb
|
@@ -147,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
151
|
requirements:
|
148
152
|
- - ">="
|
149
153
|
- !ruby/object:Gem::Version
|
150
|
-
hash:
|
154
|
+
hash: 1129571700412978294
|
151
155
|
segments:
|
152
156
|
- 0
|
153
157
|
version: "0"
|