konamio 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/konamio/sequence/requisition.rb +8 -5
- data/lib/konamio/version.rb +1 -1
- data/test/konamio/key_map_test.rb +2 -2
- data/test/konamio/sequence/requisition_test.rb +39 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1ed970c0f5489e15bc9da81a38840b1a7291b9d
|
4
|
+
data.tar.gz: 41de32e6be2d816b31d56484687cadbbae265b5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e4b589a739aa4cd6b3809e5916884d14a2f66fa37f7819c079723eaafd657c918d09549c21b1909c37370efb77ccc93cc00fe14978f3e5bc8c65bdf8b0a8f64
|
7
|
+
data.tar.gz: 4518c598111ce8e7762fe324dfbe3b949efe8c21bf3d00a675855eae92bcc19c8e64dac65e0952ff6becd60e4b76209b6df70b18fe24c97ae716158fc3c3f494
|
data/README.md
CHANGED
@@ -32,3 +32,9 @@ Okay, you can go
|
|
32
32
|
@data={:data=>{:confirmation=>"Okay, you can go"}},
|
33
33
|
@success=true>
|
34
34
|
```
|
35
|
+
|
36
|
+
You can also specify a block of code to be executed when the sequence is received successfully.
|
37
|
+
The following code would prompt the user to enter the konami code twice:
|
38
|
+
```
|
39
|
+
Konamio::Sequence::Requisition.new.execute! { Konamio::Sequence::Requisition.new.execute! }
|
40
|
+
```
|
@@ -4,6 +4,8 @@ module Konamio
|
|
4
4
|
include Konamio::KeyMap
|
5
5
|
def initialize(options={})
|
6
6
|
options = {
|
7
|
+
output: $stdout,
|
8
|
+
input: $stdin,
|
7
9
|
speaker: Konamio::Prompt,
|
8
10
|
listener: Konamio::Sequence::Listener,
|
9
11
|
sequence: [:up,:up,:down,:down,:left,:right,:left,:right,"B","A"],
|
@@ -14,21 +16,22 @@ module Konamio
|
|
14
16
|
load_options(:sequence, options)
|
15
17
|
end
|
16
18
|
|
17
|
-
def execute!
|
19
|
+
def execute! &block
|
18
20
|
prompt
|
19
|
-
|
21
|
+
result = listen(@sequence)
|
22
|
+
yield if block_given? && result.successful?
|
23
|
+
return result
|
20
24
|
end
|
21
25
|
|
22
26
|
def prompt(prompt = @prompt)
|
23
|
-
@speaker.new(prompt: prompt).execute!
|
27
|
+
@speaker.new(prompt: prompt, output: @output).execute!
|
24
28
|
end
|
25
29
|
|
26
30
|
def listen(sequence)
|
27
|
-
listener = @listener.new(sequence: sequence)
|
31
|
+
listener = @listener.new(sequence: sequence, input: @input)
|
28
32
|
received = listener.execute!
|
29
33
|
signal = received.data[:sequence]
|
30
34
|
|
31
|
-
|
32
35
|
prompt(@confirmation) and return result(true, data: { confirmation: @confirmation }) if signal.empty?
|
33
36
|
|
34
37
|
case signal
|
data/lib/konamio/version.rb
CHANGED
@@ -10,7 +10,7 @@ describe Konamio::KeyMap do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "returns the input provided if no matches are found" do
|
13
|
-
assert @subject.
|
13
|
+
assert @subject.sequence_for(:konamio) == :konamio
|
14
14
|
end
|
15
15
|
|
16
16
|
it "recognizes a number of symbols" do
|
@@ -26,7 +26,7 @@ describe Konamio::KeyMap do
|
|
26
26
|
:escape,
|
27
27
|
:konami
|
28
28
|
].each do |symbol|
|
29
|
-
assert @subject.
|
29
|
+
assert @subject.sequence_for(symbol) != symbol
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -4,18 +4,51 @@ describe Konamio::Sequence::Requisition do
|
|
4
4
|
before do
|
5
5
|
@subject = Konamio::Sequence::Requisition
|
6
6
|
@options = {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
input: @input = MiniTest::Mock.new,
|
8
|
+
output: @output = MiniTest::Mock.new,
|
9
|
+
prompt: @prompt = "Foo diddly doobardy party hardy",
|
10
|
+
listener: @listener = MiniTest::Mock.new,
|
11
|
+
speaker: @speaker = MiniTest::Mock.new,
|
12
|
+
sequence: @sequence = ["a"],
|
13
|
+
confirmation: @confirmation = "Good job, you."
|
12
14
|
}
|
15
|
+
|
16
|
+
@speaker_instance = MiniTest::Mock.new
|
17
|
+
@speaker_result = MiniTest::Mock.new
|
18
|
+
@speaker_instance.expect(:execute!, @speaker_result)
|
19
|
+
|
20
|
+
@listener_instance = MiniTest::Mock.new
|
21
|
+
@listener_result = MiniTest::Mock.new
|
22
|
+
@listener_instance.expect(:execute!, @listener_result)
|
23
|
+
|
24
|
+
@speaker.expect(:new, @speaker_instance, [{ prompt: @prompt, output: @output }])
|
25
|
+
@listener.expect(:new, @listener_instance, [{ sequence: @sequence, input: @input }])
|
26
|
+
@data_hash = MiniTest::Mock.new
|
27
|
+
@listener_result.expect(:data, @data_hash)
|
28
|
+
@data_hash.expect(:[], "", [:sequence])
|
29
|
+
|
30
|
+
@speaker_confirmation_instance = MiniTest::Mock.new
|
31
|
+
@speaker_confirmation_result = MiniTest::Mock.new
|
32
|
+
@speaker.expect(:new, @speaker_confirmation_instance, [{ prompt: @confirmation, output: @output }])
|
33
|
+
@speaker_confirmation_instance.expect(:execute!, @speaker_confirmation_result)
|
13
34
|
end
|
14
35
|
|
15
36
|
it "can be initialized" do
|
16
37
|
@subject.must_respond_to :new
|
17
38
|
end
|
18
39
|
|
19
|
-
it "
|
40
|
+
it "must execute" do
|
41
|
+
@subject.new(@options).must_respond_to :execute!
|
42
|
+
end
|
43
|
+
|
44
|
+
it "must return a result object" do
|
45
|
+
assert @subject.new(@options).execute!.successful?
|
46
|
+
end
|
47
|
+
|
48
|
+
it "will execute a block on success" do
|
49
|
+
@block_speaker_instance = MiniTest::Mock.new
|
50
|
+
@block_speaker_instance.expect(:execute!, @speaker_result)
|
51
|
+
@speaker.expect(:new, @speaker_instance, [{ prompt: "konamio!", output: @output }])
|
52
|
+
assert @subject.new(@options).execute! { @speaker.new(prompt: "konamio!", output: @output) }
|
20
53
|
end
|
21
54
|
end
|