class Gm::Notepad::LineEvaluator
Responsible for recording entries and then dumping them accordingly.
Constants
- TEXT_TO_EXPAND_REGEXP
Public Instance Methods
call(line:, expand_line: true)
click to toggle source
# File lib/gm/notepad/line_evaluator.rb, line 15 def call(line:, expand_line: true) input = ThroughputText.new(original_text: line, table_registry: table_registry) return input unless expand_line parse(input: input) input end
Private Instance Methods
parse(input:)
click to toggle source
# File lib/gm/notepad/line_evaluator.rb, line 25 def parse(input:) lives = 0 while match = input.match(TEXT_TO_EXPAND_REGEXP) lives += 1 if lives > time_to_live raise ExceededTimeToLiveError.new(text: input.original_text, time_to_live: time_to_live, text_when_time_to_live_exceeded: input.to_s) end rolled_text = Evaluators::DiceEvaluator.call(text: match[:text]) # We sent the text through a dice roller. It came back unchanged, therefore # the text is not a dice expression. Now expand the table. if rolled_text == match[:text] table_lookup = Parameters::TableLookup.new(text: match[:text], roll_dice: true) entry = table_registry.lookup(**table_lookup.parameters) input.sub!(match[:text_container], entry) else input.sub!(match[:text_container], rolled_text) end end end