class RpgLib::Parser::DiceParser
Attributes
parser[R]
Public Class Methods
new()
click to toggle source
# File lib/rpg_lib/parser/dice_parser.rb, line 9 def initialize @parser = DiceExpressionParser.new @cache = {} end
Public Instance Methods
parse(dice)
click to toggle source
# File lib/rpg_lib/parser/dice_parser.rb, line 14 def parse(dice) return @cache[dice] if @cache.key?(dice) parse_new_dice(dice) end
Private Instance Methods
parse_new_dice(dice)
click to toggle source
# File lib/rpg_lib/parser/dice_parser.rb, line 21 def parse_new_dice(dice) tree = @parser.parse(dice) raise Exception, "Parse error #{@parser.failure_reason} at offset: #{@parser.index}" if tree.nil? @cache[dice] = tree tree end