class Gm::Notepad::Parameters::TableLookup
Responsible for teasing apart the table logic
Constants
- CELL_AND_INDEX_DECLARED_REGEXP
- WITH_EMPTY_GREP_REGEX
- WITH_EMPTY_INDEX_REGEX
- WITH_GREP_REGEXP
- WITH_INDEX_REGEXP
Attributes
cell[RW]
grep[RW]
index[RW]
table_name[RW]
Public Class Methods
new(text:, roll_dice: false)
click to toggle source
# File lib/gm/notepad/parameters/table_lookup.rb, line 7 def initialize(text:, roll_dice: false) @text = text.strip @role_dice = false @parameters = {} extract_parameters! roll_them_bones! if roll_dice end
Public Instance Methods
parameters()
click to toggle source
# File lib/gm/notepad/parameters/table_lookup.rb, line 17 def parameters parameters = { table_name: table_name } parameters[:grep] = grep if grep parameters[:index] = index if index parameters[:cell] = cell if cell parameters end
Private Instance Methods
extract_parameters!()
click to toggle source
TODO: Revisit this method to see if I can remove some pre-amble
# File lib/gm/notepad/parameters/table_lookup.rb, line 46 def extract_parameters! text = @text if match = CELL_AND_INDEX_DECLARED_REGEXP.match(text) self.index = match[:index] if match[:index].present? self.cell = match[:cell] if match[:cell].present? text = text.sub(match[:declaration], '') elsif match = WITH_EMPTY_INDEX_REGEX.match(text) text = text.sub(match[:declaration], '') elsif match = WITH_INDEX_REGEXP.match(text) text = text.sub(match[:declaration], '') self.index = match[:found] elsif match = WITH_EMPTY_GREP_REGEX.match(text) text = text.sub(match[:declaration], '') elsif match = WITH_GREP_REGEXP.match(text) text = text.sub(match[:declaration], '') self.grep = match[:found] end self.table_name = text.downcase end
roll_them_bones!()
click to toggle source
# File lib/gm/notepad/parameters/table_lookup.rb, line 29 def roll_them_bones! if index self.index = Evaluators::DiceEvaluator.call(text: index) end if cell self.cell = Evaluators::DiceEvaluator.call(text: cell) end end