Class: Xudoku::Cli::KeyEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/xudoku/cli/key_event.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(original_event) ⇒ KeyEvent

Returns a new instance of KeyEvent.



7
8
9
# File 'lib/xudoku/cli/key_event.rb', line 7

def initialize(original_event)
  @original_event = original_event
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **kwargs) ⇒ Object



64
65
66
67
# File 'lib/xudoku/cli/key_event.rb', line 64

def method_missing(method_name, *args, **kwargs)
  # Delegate all unknown events to original event
  @original_event.send(method_name, *args, **kwargs)
end

Instance Method Details

#backspace?Boolean Also known as: delete?

Returns:

  • (Boolean)


31
32
33
# File 'lib/xudoku/cli/key_event.rb', line 31

def backspace?
  key.name == :backspace
end

#digitObject



40
41
42
# File 'lib/xudoku/cli/key_event.rb', line 40

def digit
  value.to_i
end

#digit?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/xudoku/cli/key_event.rb', line 36

def digit?
  value.to_s.match?(/\d/)
end

#down?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/xudoku/cli/key_event.rb', line 15

def down?
  key.name == :down  || %w[j s].include?(value)
end

#left?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/xudoku/cli/key_event.rb', line 19

def left?
  key.name == :left  || %w[h a].include?(value)
end

Returns:

  • (Boolean)


48
49
50
# File 'lib/xudoku/cli/key_event.rb', line 48

def menu?
  value.downcase == "b"
end

#quit?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/xudoku/cli/key_event.rb', line 44

def quit?
  value.downcase == "q"
end

#respond_to_missing?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/xudoku/cli/key_event.rb', line 60

def respond_to_missing?(method_name)
  @original_event.respond_to?(method_name)
end

#restart?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/xudoku/cli/key_event.rb', line 52

def restart?
  value.downcase == "r"
end

#return?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/xudoku/cli/key_event.rb', line 27

def return?
  key.name == :return
end

#right?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/xudoku/cli/key_event.rb', line 23

def right?
  key.name == :right || %w[d l].include?(value)
end

#undo?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/xudoku/cli/key_event.rb', line 56

def undo?
  value.downcase == "u"
end

#up?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/xudoku/cli/key_event.rb', line 11

def up?
  key.name == :up    || %w[w k].include?(value)
end