Class: Gm::Notepad::App

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/gm/notepad/app.rb

Overview

Responsible for recording entries and then dumping them accordingly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, input_processor: nil, renderer: nil) ⇒ App

Returns a new instance of App.



16
17
18
19
20
21
22
23
24
# File 'lib/gm/notepad/app.rb', line 16

def initialize(*args, input_processor: nil, renderer: nil)
  super
  # Note: I could note use Dry::Initializer.option with Container as I ended
  # up with multiple table registry objects created. Which is why I'm using the
  # keyword's with nil, so I can set two elements after the table_registry is "resolved"
  @renderer = renderer || LineRenderer.new(table_registry: table_registry)
  @input_processor = input_processor || InputProcessor.new(table_registry: table_registry)
  open!
end

Instance Attribute Details

#input_processorObject (readonly)

Returns the value of attribute input_processor.



25
26
27
# File 'lib/gm/notepad/app.rb', line 25

def input_processor
  @input_processor
end

#rendererObject (readonly)

Returns the value of attribute renderer.



25
26
27
# File 'lib/gm/notepad/app.rb', line 25

def renderer
  @renderer
end

Instance Method Details

#close!Object



32
33
34
# File 'lib/gm/notepad/app.rb', line 32

def close!
  renderer.close!
end

#process(text:) ⇒ Object



27
28
29
30
# File 'lib/gm/notepad/app.rb', line 27

def process(text:)
  output = input_processor.convert_to_output(input: text)
  renderer.render(output: output)
end