konamio 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be14bb94a4354ba1896b52ad536ff6cf36e29b17
4
+ data.tar.gz: 0a23d2a6923744f6d19cd53638a64d15c6d56b25
5
+ SHA512:
6
+ metadata.gz: 008311b489c40171950903bfd3abfafc9a7f41d52f1a98a8aca86308736ef5076550bc8ccd7b15c306728ce0748de68cabcadee76469c44880ec6c7267513267
7
+ data.tar.gz: 739859a5d69e6d55fc1518d1cf3c2f369f3ddc9d68ff4df2c5167d71ab9a1e0ab0769084897d78098954eb3077215287331dff7cc5cbece7e1b3d31af47bc386
@@ -1,13 +1,20 @@
1
1
  module Konamio
2
2
  class Prompt < PayDirt::Base
3
3
  def initialize(options)
4
- load_options(:prompt, options)
4
+ options = {
5
+ output: $stdout
6
+ }.merge(options)
5
7
 
6
- prompt(@prompt)
8
+ load_options(:output, :prompt, options)
7
9
  end
8
10
 
9
- def prompt(prompt)
10
- puts prompt
11
+ def execute!
12
+ @output.puts @prompt
13
+ return PayDirt::Result.new(success: true, data: { prompted: @prompt })
14
+ end
15
+
16
+ def prompt
17
+ @output.puts @prompt
11
18
  end
12
19
  end
13
20
  end
@@ -7,20 +7,20 @@ module Konamio
7
7
  end
8
8
 
9
9
  def execute!
10
- result = listen(@sequence)
10
+ result = listen
11
11
 
12
12
  if result == true
13
13
  return PayDirt::Result.new(success: true, data: { sequence: @sequence[1..-1]})
14
14
  elsif result == false
15
- return PayDirt::Result.new(success: false)
15
+ return PayDirt::Result.new(success: false, data: {})
16
16
  elsif result.nil?
17
17
  return PayDirt::Result.new(success: false, data: {terminate: true })
18
18
  end
19
19
  end
20
20
 
21
- def listen(sequence)
21
+ def listen
22
22
  case @input.getch
23
- when sequence[0]
23
+ when @sequence[0]
24
24
  true
25
25
  when "\e"
26
26
  nil
@@ -3,24 +3,26 @@ module Konamio
3
3
  class Requisition < PayDirt::Base
4
4
  def initialize(options={})
5
5
  options = {
6
- sequence: "\e[A\e[A\e[B\e[B\e[D\e[C\e[D\e[CBA",
6
+ speaker: Konamio::Prompt,
7
+ listener: Konamio::Sequence::Listener,
8
+ sequence: "\e[A\e[A\e[B\e[B\e[D\e[C\e[D\e[CBA",
7
9
  prompt: "Enter konami code (or hit escape)",
8
10
  confirmation: "Good job, you."
9
11
  }.merge(options)
10
12
 
11
13
  load_options(:sequence, options)
12
14
 
13
- prompt(@prompt)
15
+ prompt
14
16
  listen(@sequence)
15
17
  finish(false)
16
18
  end
17
19
 
18
- def prompt(prompt)
19
- Konamio::Prompt.new(prompt: prompt)
20
+ def prompt
21
+ @speaker.new(prompt: @prompt).execute!
20
22
  end
21
23
 
22
24
  def listen(sequence)
23
- listener = Konamio::Sequence::Listener.new(sequence: sequence)
25
+ listener = @listener.new(sequence: sequence)
24
26
  received = listener.execute!
25
27
 
26
28
  if received.successful?
@@ -32,7 +34,7 @@ module Konamio
32
34
  elsif received.data[:terminate]
33
35
  finish(false)
34
36
  else
35
- prompt(@prompt)
37
+ prompt
36
38
  listen(@sequence)
37
39
  end
38
40
  end
@@ -1,3 +1,3 @@
1
1
  module Konamio
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,18 @@
1
+ require "minitest_helper"
2
+
3
+ describe Konamio::Prompt do
4
+ before do
5
+ @subject = Konamio::Prompt
6
+ @prompt = rand(100000).to_s
7
+ @output = MiniTest::Mock.new
8
+
9
+ @output.expect(:puts, nil, [@prompt])
10
+ end
11
+
12
+ it "can be initialized" do
13
+ @subject.must_respond_to :new
14
+ prompted = @subject.new(prompt: @prompt, output: @output).execute!
15
+ assert prompted.successful?
16
+ assert @output.verify
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ require "minitest_helper"
2
+
3
+ describe Konamio::Sequence::Listener do
4
+ before do
5
+ @subject = Konamio::Sequence::Listener
6
+
7
+ @sequence = "a"
8
+ @input = MiniTest::Mock.new
9
+ end
10
+
11
+ it "can be initialized" do
12
+ @subject.must_respond_to :new
13
+ end
14
+
15
+ it "knows when you're right" do
16
+ @input.expect(:getch, "a")
17
+ result = @subject.new(sequence: @sequence, input: @input).execute!
18
+
19
+ assert @input.verify
20
+ assert result.successful?
21
+ end
22
+
23
+ it "knows when you're right" do
24
+ @input.expect(:getch, "b")
25
+ result = @subject.new(sequence: @sequence, input: @input).execute!
26
+
27
+ assert @input.verify
28
+ assert !result.successful?
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ require "minitest_helper"
2
+
3
+ describe Konamio::Sequence::Requisition do
4
+ before do
5
+ @subject = Konamio::Sequence::Requisition
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."
12
+ }
13
+ end
14
+
15
+ it "can be initialized" do
16
+ @subject.must_respond_to :new
17
+ end
18
+ end
@@ -10,4 +10,4 @@ require "pry"
10
10
  $: << File.dirname(__FILE__) + "/../lib"
11
11
  $: << File.dirname(__FILE__)
12
12
 
13
- require "konami"
13
+ require "konamio"
metadata CHANGED
@@ -1,88 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konamio
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.2
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tad Hosford
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
  date: 2013-05-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: pay_dirt
16
- version_requirements: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ! '>='
19
- - !ruby/object:Gem::Version
20
- version: !binary |-
21
- MA==
22
- none: false
23
15
  requirement: !ruby/object:Gem::Requirement
24
16
  requirements:
25
- - - ! '>='
17
+ - - '>='
26
18
  - !ruby/object:Gem::Version
27
- version: !binary |-
28
- MA==
29
- none: false
30
- prerelease: false
19
+ version: '0'
31
20
  type: :runtime
32
- - !ruby/object:Gem::Dependency
33
- name: minitest
21
+ prerelease: false
34
22
  version_requirements: !ruby/object:Gem::Requirement
35
23
  requirements:
36
- - - ! '>='
24
+ - - '>='
37
25
  - !ruby/object:Gem::Version
38
- version: !binary |-
39
- MA==
40
- none: false
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
41
29
  requirement: !ruby/object:Gem::Requirement
42
30
  requirements:
43
- - - ! '>='
31
+ - - '>='
44
32
  - !ruby/object:Gem::Version
45
- version: !binary |-
46
- MA==
47
- none: false
48
- prerelease: false
33
+ version: '0'
49
34
  type: :development
50
- - !ruby/object:Gem::Dependency
51
- name: pry
35
+ prerelease: false
52
36
  version_requirements: !ruby/object:Gem::Requirement
53
37
  requirements:
54
- - - ! '>='
38
+ - - '>='
55
39
  - !ruby/object:Gem::Version
56
- version: !binary |-
57
- MA==
58
- none: false
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
59
43
  requirement: !ruby/object:Gem::Requirement
60
44
  requirements:
61
- - - ! '>='
45
+ - - '>='
62
46
  - !ruby/object:Gem::Version
63
- version: !binary |-
64
- MA==
65
- none: false
66
- prerelease: false
47
+ version: '0'
67
48
  type: :development
68
- - !ruby/object:Gem::Dependency
69
- name: rake
49
+ prerelease: false
70
50
  version_requirements: !ruby/object:Gem::Requirement
71
51
  requirements:
72
- - - ! '>='
52
+ - - '>='
73
53
  - !ruby/object:Gem::Version
74
- version: !binary |-
75
- MA==
76
- none: false
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
77
57
  requirement: !ruby/object:Gem::Requirement
78
58
  requirements:
79
- - - ! '>='
59
+ - - '>='
80
60
  - !ruby/object:Gem::Version
81
- version: !binary |-
82
- MA==
83
- none: false
84
- prerelease: false
61
+ version: '0'
85
62
  type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
86
69
  description: Recognize sequences in Ruby... just for fun.
87
70
  email:
88
71
  - tad.hosford@gmail.com
@@ -101,37 +84,31 @@ files:
101
84
  - lib/konamio/sequence/listener.rb
102
85
  - lib/konamio/sequence/requisition.rb
103
86
  - lib/konamio/version.rb
87
+ - test/konamio/prompt_test.rb
88
+ - test/konamio/sequence/listener_test.rb
89
+ - test/konamio/sequence/requisition_test.rb
104
90
  - test/minitest_helper.rb
105
91
  homepage: https://github.com/rthbound/konamio
106
92
  licenses: []
107
- post_install_message:
93
+ metadata: {}
94
+ post_install_message:
108
95
  rdoc_options: []
109
96
  require_paths:
110
97
  - lib
111
98
  required_ruby_version: !ruby/object:Gem::Requirement
112
99
  requirements:
113
- - - ! '>='
100
+ - - '>='
114
101
  - !ruby/object:Gem::Version
115
- segments:
116
- - 0
117
- hash: 2
118
- version: !binary |-
119
- MA==
120
- none: false
102
+ version: '0'
121
103
  required_rubygems_version: !ruby/object:Gem::Requirement
122
104
  requirements:
123
- - - ! '>='
105
+ - - '>='
124
106
  - !ruby/object:Gem::Version
125
- segments:
126
- - 0
127
- hash: 2
128
- version: !binary |-
129
- MA==
130
- none: false
107
+ version: '0'
131
108
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 1.8.24
134
- signing_key:
135
- specification_version: 3
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.0.rc.2
111
+ signing_key:
112
+ specification_version: 4
136
113
  summary: I'm gonna recognize the konami sequence
137
114
  test_files: []