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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61d4aed1d5bd09a19bb68f6f00d110ced5c6701d
4
- data.tar.gz: e9b3517d2be70b3460f48ee619196a82d7932570
3
+ metadata.gz: b1ed970c0f5489e15bc9da81a38840b1a7291b9d
4
+ data.tar.gz: 41de32e6be2d816b31d56484687cadbbae265b5a
5
5
  SHA512:
6
- metadata.gz: d40dba91a972dae2e26a6d2734dc01139783f434b73544b0b9321bab6c999670520e07f4829ce925e1205bc9ad1006a87a45e06d1dbd04efcba709508e8cf431
7
- data.tar.gz: 6e3b7879dd016fb30338399d25b78d0add6ee154affad1e807dddb5e59ed3da4944d63e939b9e9bef481e9b75b40273c4827ec41c9d63ff3add107e76cb7d13a
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
- return listen(@sequence)
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
@@ -1,3 +1,3 @@
1
1
  module Konamio
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.sequence(:konamio) == :konamio
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.sequence(symbol) != symbol
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
- prompt: "Foo diddly doobardy party hardy",
8
- listener: @listener = MiniTest::Mock.new,
9
- sequence: "a",
10
- speaker: @speaker = MiniTest::Mock.new,
11
- confirmation: "Good job, you."
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 "returns a result object" do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konamio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tad Hosford