Class: Gm::Notepad::InputHandlers::WriteToTableHandler

Inherits:
DefaultHandler
  • Object
show all
Defined in:
lib/gm/notepad/input_handlers/write_to_table_handler.rb

Constant Summary collapse

WITH_WRITE_TARGET_REGEXP =
%r{\A\<(?<table_name>[^:]+):(?<line>.*)}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DefaultHandler

build_if_handled, #initialize, #lines

Constructor Details

This class inherits a constructor from Gm::Notepad::InputHandlers::DefaultHandler

Class Method Details

.handles?(input:) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/gm/notepad/input_handlers/write_to_table_handler.rb', line 8

def self.handles?(input:)
  return true if input.match(WITH_WRITE_TARGET_REGEXP)
end

Instance Method Details

#after_initialize!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gm/notepad/input_handlers/write_to_table_handler.rb', line 12

def after_initialize!
  match = input.match(WITH_WRITE_TARGET_REGEXP)
  input.text_to_evaluate = match[:line].strip
  table_name = match[:table_name]
  table_name = table_name.downcase
  input.for_rendering(
    table_name: table_name,
    text: input.text_to_evaluate,
    to_interactive: true,
    to_output: false,
    to_filesystem: true,
    expand_line: true
  )
end