Class: Gm::Notepad::ThroughputText

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

Overview

Keep the original text close to the text that we are changing. This way we can dump the original text as a comment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ThroughputText

Returns a new instance of ThroughputText.



11
12
13
14
15
# File 'lib/gm/notepad/throughput_text.rb', line 11

def initialize(*args)
  super
  self.text_to_evaluate = original_text.strip
  original_text.freeze
end

Instance Attribute Details

#text_to_evaluateObject

Returns the value of attribute text_to_evaluate.



17
18
19
# File 'lib/gm/notepad/throughput_text.rb', line 17

def text_to_evaluate
  @text_to_evaluate
end

Instance Method Details

#[](*args) ⇒ Object



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

def [](*args)
  @text_to_evaluate[*args]
end

#evaluate!Object



49
50
51
52
53
# File 'lib/gm/notepad/throughput_text.rb', line 49

def evaluate!
  lines_for_rendering.each do |line|
    line.expand!
  end
end

#for_rendering(text:, **kwargs) ⇒ Object



41
42
43
# File 'lib/gm/notepad/throughput_text.rb', line 41

def for_rendering(text:, **kwargs)
  @lines_for_rendering << LineForRendering.new(text: text, table_registry: table_registry, **kwargs)
end

#lines_for_renderingObject Also known as: lines



55
56
57
# File 'lib/gm/notepad/throughput_text.rb', line 55

def lines_for_rendering
  @lines_for_rendering
end

#match(regexp) ⇒ Object



19
20
21
# File 'lib/gm/notepad/throughput_text.rb', line 19

def match(regexp)
  text_to_evaluate.match(regexp)
end

#render_current_text(**kwargs) ⇒ Object



45
46
47
# File 'lib/gm/notepad/throughput_text.rb', line 45

def render_current_text(**kwargs)
  for_rendering(text: text_to_evaluate, **kwargs)
end

#sub!(from, to) ⇒ Object



23
24
25
# File 'lib/gm/notepad/throughput_text.rb', line 23

def sub!(from, to)
  @text_to_evaluate = text_to_evaluate.sub(from, to)
end

#to_sObject



35
36
37
# File 'lib/gm/notepad/throughput_text.rb', line 35

def to_s
  @text_to_evaluate.to_s
end

#to_strObject



31
32
33
# File 'lib/gm/notepad/throughput_text.rb', line 31

def to_str
  @text_to_evaluate.to_str
end