Class: DialogTui::UserAction::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/dialog_tui/user_action/action.rb

Constant Summary collapse

CHARS =

any other mapping can be passed into constructor! sounds odd to pass it here, builder is a better idea, anyway strange class + builder hereā€¦

{
  ctrl_c: "\u0003",
  space:  ' ',

  esc:     "\e",
  escape:  "\e",

  enter:  "\r",
  return: "\r",

  up:    "\e[A",
  down:  "\e[B",
  right: "\e[C",
  left:  "\e[D",
}

Instance Method Summary collapse

Constructor Details

#initialize(name, mapping = CHARS, &block) ⇒ Action

Returns a new instance of Action.



5
6
7
8
# File 'lib/dialog_tui/user_action/action.rb', line 5

def initialize name, mapping=CHARS, &block
  @matches = mapping.fetch name.to_sym
  @block = block
end

Instance Method Details

#callObject



19
20
21
# File 'lib/dialog_tui/user_action/action.rb', line 19

def call
  @block.call
end

#match?(input) ⇒ Boolean Also known as: matches?

Returns:

  • (Boolean)


13
14
15
# File 'lib/dialog_tui/user_action/action.rb', line 13

def match? input
  matches == input
end