class Gm::Notepad::InputHandlers::QueryTableHandler
Constants
- QUERY_TABLE_NAMES_PREFIX
Public Class Methods
handles?(input:)
click to toggle source
# File lib/gm/notepad/input_handlers/query_table_handler.rb, line 10 def self.handles?(input:) # Does not have the table prefix return false unless input.match(/^\+/) # It is only the table prefix return false if input.match(/^\+$/) # It is querying all tables by way of grep return false if input.match(/^\+\//) true end
Public Instance Methods
after_initialize!()
click to toggle source
# File lib/gm/notepad/input_handlers/query_table_handler.rb, line 20 def after_initialize! line = input[1..-1].to_s @table_lookup_parameters = Parameters::TableLookup.new(text: line) evaluate_lines! end
evaluate_lines!()
click to toggle source
# File lib/gm/notepad/input_handlers/query_table_handler.rb, line 29 def evaluate_lines! begin table = table_registry.fetch_table(name: table_name) rescue MissingTableError message = "Unknown table #{table_name.inspect}. Did you mean: " message += table_registry.table_names.grep(/\A#{table_name}/).map(&:inspect).join(", ") input.for_rendering(text: message, to_output: false, to_interactive: true, expand_line: false) return end if index begin text = table.lookup(index: index) input.for_rendering(text: text, to_output: false, to_interactive: true, expand_line: false) rescue MissingTableEntryError input.for_rendering(text: %(Entry with index "#{index}" not found in "#{table_name}" table), to_interactive: true, to_output: false) end elsif grep regexp = %r{#{grep}}i table.grep(regexp).each do |text| input.for_rendering(text: text, to_output: false, to_interactive: true, expand_line: false) end else table.all.each do |text| input.for_rendering(text: text, to_output: false, to_interactive: true, expand_line: false) end end end