class Gm::Notepad::LineRenderer
Responsible for rendering lines to the corresponding buffers
Public Instance Methods
call(lines, to_output: false, to_interactive: true, as_of: Time.now)
click to toggle source
# File lib/gm/notepad/line_renderer.rb, line 32 def call(lines, to_output: false, to_interactive: true, as_of: Time.now) render_interactive(lines) if to_interactive render_output(lines, as_of: as_of) if to_output end
close!()
click to toggle source
# File lib/gm/notepad/line_renderer.rb, line 37 def close! interactive_buffer.close! output_buffer.close! end
render(output:, as_of: Time.now)
click to toggle source
# File lib/gm/notepad/line_renderer.rb, line 16 def render(output:, as_of: Time.now) output.evaluate! output.lines_for_rendering.each do |line| next unless line.to_interactive render_interactive(line) end output.lines_for_rendering.each do |line| next unless line.to_output render_output(line, as_of: as_of) end output.lines_for_rendering.each do |line| next unless line.to_filesystem render_filesystem(line) end end
Private Instance Methods
each_expanded_line(lines:) { |line| ... }
click to toggle source
Gracefully expand the t and n for the output buffer
# File lib/gm/notepad/line_renderer.rb, line 68 def each_expanded_line(lines:) Array(lines).each do |unexpanded_line| String(unexpanded_line).split('\\n').each do |line| line = line.gsub('\\t', "\t") yield(line) end end end
render_filesystem(lines)
click to toggle source
# File lib/gm/notepad/line_renderer.rb, line 59 def render_filesystem(lines) return unless lines.table_name table_name = lines.table_name each_expanded_line(lines: lines) do |line| table_registry.append(table_name: table_name, line: line, write: true) end end
render_interactive(lines)
click to toggle source
# File lib/gm/notepad/line_renderer.rb, line 53 def render_interactive(lines) each_expanded_line(lines: lines) do |line| interactive_buffer.puts(line) end end
render_output(lines, as_of:)
click to toggle source
# File lib/gm/notepad/line_renderer.rb, line 44 def render_output(lines, as_of:) each_expanded_line(lines: lines) do |line| if with_timestamp line = "#{as_of}\t#{line}" end output_buffer.puts(line) end end