Class: RpgLib::Parser::DiceParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rpg_lib/parser/dice_parser.rb

Overview

DiceParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDiceParser

Returns a new instance of DiceParser.



9
10
11
12
# File 'lib/rpg_lib/parser/dice_parser.rb', line 9

def initialize
  @parser = DiceExpressionParser.new
  @cache = {}
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



7
8
9
# File 'lib/rpg_lib/parser/dice_parser.rb', line 7

def parser
  @parser
end

Instance Method Details

#parse(dice) ⇒ Object



14
15
16
17
# 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