Class: BagOfHolding::Dice::DieValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/bag_of_holding/dice/die_validator.rb

Overview

Internal: Wraps the logic that determines if a die can be rolled successfully

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(die:) ⇒ DieValidator

Returns a new instance of DieValidator.



12
13
14
# File 'lib/bag_of_holding/dice/die_validator.rb', line 12

def initialize(die:)
  self.die = die
end

Instance Attribute Details

#dieObject

Returns the value of attribute die.



10
11
12
# File 'lib/bag_of_holding/dice/die_validator.rb', line 10

def die
  @die
end

Class Method Details

.valid?(die) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/bag_of_holding/dice/die_validator.rb', line 6

def self.valid?(die)
  new(die: die).valid?
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/bag_of_holding/dice/die_validator.rb', line 16

def valid?
  return false unless die.sides
  return false if die.reroll && die.explode && die.reroll >= die.explode
  true
end