Class: Gm::Notepad::InputHandlers::WriteToTableHandler
- Inherits:
-
DefaultHandler
- Object
- DefaultHandler
- Gm::Notepad::InputHandlers::WriteToTableHandler
- Defined in:
- lib/gm/notepad/input_handlers/write_to_table_handler.rb
Constant Summary collapse
- HANDLED_PREFIX =
"<".freeze
- NON_EXPANDING_CHARATER =
'!'.freeze
- WITH_INDEX_REGEXP =
%r{(?<declaration>\[(?<index>[^\]]+)\])}- WITH_GREP_REGEXP =
%r{(?<declaration>\/(?<grep>[^\/]+)/)}- WITH_WRITE_TARGET_REGEXP =
%r{\A#{HANDLED_PREFIX}(?<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
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(/^\</) end |
Instance Method Details
#after_initialize! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gm/notepad/input_handlers/write_to_table_handler.rb', line 16 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], '') index = index_match[:index] elsif grep_match = WITH_GREP_REGEXP.match(table_name) table_name = table_name.sub(grep_match[:declaration], '') grep = grep_match[:grep] end table_name = table_name.downcase else raise "I don't know what to do" end if input.match(/^\!/) = false input.sub!(/^\!/, '') else = true end input.for_rendering(table_name: table_name, text: input.text_to_evaluate, to_interactive: true , to_output: false, to_filesystem: true, expand_line: ) end |