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
- NON_EXPANDING_CHARATER =
'!'.freeze
- WITH_INDEX_REGEXP =
%r{(?<declaration>\[(?<index>[^\]]+)\])}- WITH_GREP_REGEXP =
%r{(?<declaration>\/(?<grep>[^\/]+)/)}- WITH_WRITE_TARGET_REGEXP =
%r{\A<(?<table_name>[^>]+)>(?<line>.*)}
Instance Attribute Summary collapse
-
#grep ⇒ Object
Returns the value of attribute grep.
-
#index ⇒ Object
Returns the value of attribute index.
-
#line ⇒ Object
Returns the value of attribute line.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Attributes inherited from DefaultHandler
#expand_line, #input, #table_registry, #to_filesystem, #to_interactive, #to_output
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from DefaultHandler
build_if_handled, #each_line_with_parameters, #initialize
Constructor Details
This class inherits a constructor from Gm::Notepad::InputHandlers::DefaultHandler
Instance Attribute Details
#grep ⇒ Object
Returns the value of attribute grep.
11 12 13 |
# File 'lib/gm/notepad/input_handlers/write_to_table_handler.rb', line 11 def grep @grep end |
#index ⇒ Object
Returns the value of attribute index.
11 12 13 |
# File 'lib/gm/notepad/input_handlers/write_to_table_handler.rb', line 11 def index @index end |
#line ⇒ Object
Returns the value of attribute line.
11 12 13 |
# File 'lib/gm/notepad/input_handlers/write_to_table_handler.rb', line 11 def line @line end |
#table_name ⇒ Object
Returns the value of attribute table_name.
11 12 13 |
# File 'lib/gm/notepad/input_handlers/write_to_table_handler.rb', line 11 def table_name @table_name end |
Class Method Details
.handles?(input:) ⇒ Boolean
7 8 9 |
# File 'lib/gm/notepad/input_handlers/write_to_table_handler.rb', line 7 def self.handles?(input:) return true if input[0] == "<" 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 39 40 41 |
# File 'lib/gm/notepad/input_handlers/write_to_table_handler.rb', line 16 def after_initialize! self.to_filesystem = true self.to_interactive = true if match = WITH_WRITE_TARGET_REGEXP.match(input) line = 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 line[0] == NON_EXPANDING_CHARATER self. = false self.line = line[1..-1] else self. = true end self.line = line.strip end |
#lines ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gm/notepad/input_handlers/write_to_table_handler.rb', line 43 def lines if index elsif grep end if else end table_registry.append(table_name: table_name, line: line, write: true) [] end |