konamio 0.1.1 → 0.1.4

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: 64567479769f776f55124c2cc781254b13bb00d2
4
- data.tar.gz: fce728a4fa000545e348f620e55d130acd192944
3
+ metadata.gz: 61d4aed1d5bd09a19bb68f6f00d110ced5c6701d
4
+ data.tar.gz: e9b3517d2be70b3460f48ee619196a82d7932570
5
5
  SHA512:
6
- metadata.gz: f19d56779d7d3f2475ed57249b06b23990449325714d5f896fe33b61e00c76807d38cd8ed1c699f271959c25f1544ffc83a46afdb1c55b9fe7f6c1a95e285cc6
7
- data.tar.gz: cc2ee72ba0372c95271e8fdf3975171fbbf339826491afdeb4f1394c96bbd5027a69173076aa7474efe79e29c49ac6cdb4573cb739de43048f061251890400cb
6
+ metadata.gz: d40dba91a972dae2e26a6d2734dc01139783f434b73544b0b9321bab6c999670520e07f4829ce925e1205bc9ad1006a87a45e06d1dbd04efcba709508e8cf431
7
+ data.tar.gz: 6e3b7879dd016fb30338399d25b78d0add6ee154affad1e807dddb5e59ed3da4944d63e939b9e9bef481e9b75b40273c4827ec41c9d63ff3add107e76cb7d13a
@@ -1,17 +1,20 @@
1
1
  module Konamio
2
2
  module KeyMap
3
- def self.sequence(key)
4
- {
5
- space: " ",
6
- tab: "\t",
7
- return: "\r",
8
- line_feed: "\n",
9
- escape: "\e",
10
- up: "\e[A",
11
- down: "\e[B",
12
- right: "\e[C",
13
- left: "\e[D"
14
- }.fetch(key) { key }
3
+ def self.included(base)
4
+ def sequence_for(key)
5
+ {
6
+ space: " ",
7
+ tab: "\t",
8
+ return: "\r",
9
+ line_feed: "\n",
10
+ escape: "\e",
11
+ up: "\e[A",
12
+ down: "\e[B",
13
+ right: "\e[C",
14
+ left: "\e[D",
15
+ konami: [:up, :up, :down, :down, :left, :right, :left, :right, "B", "A"]
16
+ }.fetch(key) { key }
17
+ end
15
18
  end
16
19
  end
17
20
  end
@@ -1,6 +1,8 @@
1
1
  module Konamio
2
2
  module Sequence
3
3
  class Listener < PayDirt::Base
4
+ include Konamio::KeyMap
5
+
4
6
  def initialize(options)
5
7
  options = { input: $stdin, debounce: 0.0001 }.merge(options)
6
8
  load_options(:sequence, options)
@@ -34,7 +36,7 @@ module Konamio
34
36
  end
35
37
 
36
38
  case input
37
- when Konamio::KeyMap.sequence(@sequence[0])
39
+ when sequence_for(@sequence[0])
38
40
  true
39
41
  when "\e"
40
42
  :negative
@@ -1,6 +1,7 @@
1
1
  module Konamio
2
2
  module Sequence
3
3
  class Requisition < PayDirt::Base
4
+ include Konamio::KeyMap
4
5
  def initialize(options={})
5
6
  options = {
6
7
  speaker: Konamio::Prompt,
@@ -1,3 +1,3 @@
1
1
  module Konamio
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/konamio.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "pay_dirt"
2
2
 
3
- require_relative 'konamio/prompt'
3
+ require_relative 'konamio/key_map'
4
4
  require_relative 'konamio/sequence/listener'
5
+ require_relative 'konamio/prompt'
5
6
  require_relative 'konamio/sequence/requisition'
6
- require_relative 'konamio/key_map'
@@ -2,11 +2,15 @@ require "minitest_helper"
2
2
 
3
3
  describe Konamio::KeyMap do
4
4
  before do
5
- @subject = Konamio::KeyMap
5
+ class TestCase
6
+ include Konamio::KeyMap
7
+ end
8
+
9
+ @subject = TestCase.new
6
10
  end
7
11
 
8
12
  it "returns the input provided if no matches are found" do
9
- assert @subject.sequence(:konami) == :konami
13
+ assert @subject.sequence(:konamio) == :konamio
10
14
  end
11
15
 
12
16
  it "recognizes a number of symbols" do
@@ -19,7 +23,8 @@ describe Konamio::KeyMap do
19
23
  :tab,
20
24
  :return,
21
25
  :line_feed,
22
- :escape
26
+ :escape,
27
+ :konami
23
28
  ].each do |symbol|
24
29
  assert @subject.sequence(symbol) != symbol
25
30
  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.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tad Hosford