require "gm/notepad/input_handlers/default_handler" module Gm module Notepad module InputHandlers class WriteToTableHandler < DefaultHandler HANDLED_PREFIX = "<".freeze def self.handles?(input:) return true if input.match(/^\\[(?[^\]]+)\])} WITH_GREP_REGEXP = %r{(?\/(?[^\/]+)/)} WITH_WRITE_TARGET_REGEXP = %r{\A#{HANDLED_PREFIX}(?[^:]+):(?.*)} def after_initialize! if match = input.match(WITH_WRITE_TARGET_REGEXP) input.text_to_evaluate = match[:line].strip table_name = match[:table_name] if index_match = WITH_INDEX_REGEXP.match(table_name) table_name = table_name.sub(index_match[:declaration], '') self.index = index_match[:index] elsif grep_match = WITH_GREP_REGEXP.match(table_name) table_name = table_name.sub(grep_match[:declaration], '') self.grep = grep_match[:grep] end self.table_name = table_name.downcase else raise "I don't know what to do" end if input.match(/^\!/) expand_line = false input.sub!(/^\!/, '') else expand_line = true end input.render_current_text(to_interactive: true , to_output: false, to_filesystem: true, expand_line: expand_line) end def lines if index elsif grep end if expand_line else end table_registry.append(table_name: table_name, line: input.text_to_evaluate, write: true) [] end end end end end