Class: RpgLib::DiceRoller

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rpg_lib/dice_roller.rb

Overview

DiceRoller

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDiceRoller

Returns a new instance of DiceRoller.



30
31
32
33
# File 'lib/rpg_lib/dice_roller.rb', line 30

def initialize
  @roller = DieRoller.new
  @parser = Parser::DiceParser.new
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



27
28
29
# File 'lib/rpg_lib/dice_roller.rb', line 27

def parser
  @parser
end

#rollerObject

Returns the value of attribute roller.



28
29
30
# File 'lib/rpg_lib/dice_roller.rb', line 28

def roller
  @roller
end

Instance Method Details

#roll(dice) ⇒ Object



39
40
41
# File 'lib/rpg_lib/dice_roller.rb', line 39

def roll(dice)
  @parser.parse(dice).eval(@roller)
end

#roll_and_ignore(dice, ignored_values) ⇒ Object



43
44
45
46
47
48
# File 'lib/rpg_lib/dice_roller.rb', line 43

def roll_and_ignore(dice, ignored_values)
  loop do
    rolled_value = roll(dice)
    return rolled_value unless ignored_values.include?(rolled_value)
  end
end

#roll_die(n) ⇒ Object



35
36
37
# File 'lib/rpg_lib/dice_roller.rb', line 35

def roll_die(n)
  @roller.roll(n)
end