konamio 1.0.0 → 1.0.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9355bbc85a0b405369b30b96176d3275749a69a9
|
4
|
+
data.tar.gz: c9610b2b28cc66a1f96bce6e0f470422fc80fbff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfcb60568f3c7289ae2eec4b0ac44066e7f80216841fe7bfcef3d91f420910907a8f1ac9dc9b1426f0b2857f52be40d6400adc31e1db034b240e17bad5c4e421
|
7
|
+
data.tar.gz: d224f73499c5ced6f5e21b6976a667bc09f64792aa619d7fe786906a410ef6242b87f0fc4788220234d69be8c16d1d73d254be64910e04a9e1045c6544ed02c3
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/konamio) [](https://travis-ci.org/rthbound/konamio) [](https://coveralls.io/r/rthbound/konamio) [](https://codeclimate.com/github/rthbound/konamio)
|
4
4
|
|
5
|
-
|
6
5
|

|
7
6
|
|
8
7
|
gem install konamio
|
@@ -26,9 +25,12 @@ Good job, you.
|
|
26
25
|
|
27
26
|
#### Sequences
|
28
27
|
|
29
|
-
You can configure it to listen for any ascii based sequence you want
|
28
|
+
You can configure it to listen for any ascii based sequence you want
|
29
|
+
using the `:sequence` option. This can be specified using a string
|
30
|
+
(`"foobar"`) or an array of recognized symbols and one-character strings
|
31
|
+
(escaped charactersare okay, e.g. `[:up, "1", "2", "3", "\t"]`):
|
30
32
|
|
31
|
-
```
|
33
|
+
```
|
32
34
|
> Konamio::Sequence::Requisition.new({
|
33
35
|
sequence: "a".upto("z").to_a.reverse,
|
34
36
|
prompt: "Say the alphabet backwards",
|
@@ -43,7 +45,7 @@ Okay, you can go
|
|
43
45
|
|
44
46
|
#### Output
|
45
47
|
|
46
|
-
There are three dialogs that Konamio might send to
|
48
|
+
There are three dialogs that Konamio might send to stdout.
|
47
49
|
|
48
50
|
1. `:prompt` is the dialog displayed initially, and each time the user fails to supply the proper sequence.
|
49
51
|
2. `:confirmation` is displayed when the required sequence is entered properly.
|
@@ -53,7 +55,11 @@ You can customize any of these dialogs, or disable them individually by passing
|
|
53
55
|
|
54
56
|
#### Success!
|
55
57
|
|
56
|
-
It would be boring if all Konamio did was return a result object.
|
58
|
+
It would be boring if all Konamio did was return a result object. That's why
|
59
|
+
`Konamio::Sequence::Requisition#execute!` **takes a block**, and will execute
|
60
|
+
that block when the sequence has been successfully entered. You're limited only
|
61
|
+
by your imagination and the context of your application. Konamio will supply
|
62
|
+
the value of the sequence to the block.
|
57
63
|
|
58
64
|
The following code would prompt the user to enter the konami code twice:
|
59
65
|
```ruby
|
@@ -24,13 +24,14 @@ module Konamio
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# @api public
|
27
|
+
# @yield [sequence] Gives the sequence to the block
|
27
28
|
# @yieldreturn The result of a block, if supplied
|
28
29
|
# @return Konamio::Result
|
29
30
|
def execute! &block
|
30
31
|
prompt
|
31
32
|
|
32
33
|
result = listen(@sequence)
|
33
|
-
yield if block_given? && result.successful?
|
34
|
+
yield(@sequence) if block_given? && result.successful?
|
34
35
|
|
35
36
|
result
|
36
37
|
end
|
data/lib/konamio/version.rb
CHANGED
@@ -9,7 +9,7 @@ describe Konamio::Sequence::Requisition do
|
|
9
9
|
prompt: @prompt = false,
|
10
10
|
listener: @listener = MiniTest::Mock.new,
|
11
11
|
speaker: @speaker = MiniTest::Mock.new,
|
12
|
-
sequence: @sequence =
|
12
|
+
sequence: @sequence = "ab",
|
13
13
|
confirmation: @confirmation = false,
|
14
14
|
cancellation: false
|
15
15
|
}
|
@@ -22,10 +22,6 @@ describe Konamio::Sequence::Requisition do
|
|
22
22
|
@listener_result = MiniTest::Mock.new
|
23
23
|
@listener_instance.expect(:execute!, @listener_result)
|
24
24
|
|
25
|
-
# The @listener_result contains some data
|
26
|
-
@data_hash = MiniTest::Mock.new
|
27
|
-
@listener_result.expect(:data, @data_hash)
|
28
|
-
@data_hash.expect(:[], :negative, [:sequence])
|
29
25
|
end
|
30
26
|
|
31
27
|
it "can be initialized" do
|
@@ -37,6 +33,27 @@ describe Konamio::Sequence::Requisition do
|
|
37
33
|
end
|
38
34
|
|
39
35
|
it "can be cancelled" do
|
36
|
+
# The @listener_result contains some data
|
37
|
+
@data_hash = MiniTest::Mock.new
|
38
|
+
@listener_result.expect(:data, @data_hash)
|
39
|
+
@data_hash.expect(:[], :negative, [:sequence])
|
40
|
+
|
41
|
+
assert !@subject.new(@options).execute!.successful?
|
42
|
+
end
|
43
|
+
|
44
|
+
it "will listen for the next character" do
|
45
|
+
# This will happen a second time
|
46
|
+
@listener.expect(:new, @listener_instance, [{ sequence: "b", input: @input }])
|
47
|
+
@listener_instance.expect(:execute!, @listener_result)
|
48
|
+
|
49
|
+
# The @listener_result contains some data
|
50
|
+
@data_hash = MiniTest::Mock.new
|
51
|
+
@listener_result.expect(:data, @data_hash)
|
52
|
+
@data_hash.expect(:[], "b", [:sequence])
|
53
|
+
|
54
|
+
@listener_result.expect(:data, @data_hash)
|
55
|
+
@data_hash.expect(:[], :negative, [:sequence])
|
56
|
+
|
40
57
|
assert !@subject.new(@options).execute!.successful?
|
41
58
|
end
|
42
59
|
end
|
@@ -59,4 +59,13 @@ describe Konamio::Sequence::Requisition do
|
|
59
59
|
@speaker.expect(:new, @speaker_instance, [{ prompt: "konamio!", output: @output }])
|
60
60
|
assert @subject.new(@options).execute! { @speaker.new(prompt: "konamio!", output: @output) }
|
61
61
|
end
|
62
|
+
|
63
|
+
it "will pass the sequence to the block" do
|
64
|
+
truth = false
|
65
|
+
assert @subject.new(@options).execute! { |seq|
|
66
|
+
truth = !truth if @sequence == seq
|
67
|
+
}
|
68
|
+
|
69
|
+
assert truth
|
70
|
+
end
|
62
71
|
end
|
data/test/minitest_helper.rb
CHANGED