Sha256: 96b5b0cbc373c0acaa0885ffe95e0a8ed4a038a85ad63510d66bf1142818c0b3

Contents?: true

Size: 853 Bytes

Versions: 1

Compression:

Stored size: 853 Bytes

Contents

require "gm/notepad/input_handlers/default_handler"

module Gm
  module Notepad
    module InputHandlers
      class WriteToTableHandler < DefaultHandler
        WITH_WRITE_TARGET_REGEXP = %r{\A\<(?<table_name>[^:]+):(?<line>.*)}
        def self.handles?(input:)
          return true if input.match(WITH_WRITE_TARGET_REGEXP)
        end

        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
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gm-notepad-0.0.18 lib/gm/notepad/input_handlers/write_to_table_handler.rb