Class: ParaDice::Bag

Inherits:
Object
  • Object
show all
Defined in:
lib/para_dice/bag.rb

Overview

Class to provide a convienent container for and roller of dice

Direct Known Subclasses

GothamDice, StarWarsDice

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_readersArray<#resolve>

Returns default: [].

Returns:

  • (Array<#resolve>)

    default: []



18
# File 'lib/para_dice/bag.rb', line 18

attribute :default_readers, Array, default: []

#diceHash<String,Die>

Returns default: {}.

Returns:

  • (Hash<String,Die>)

    default: {}



15
# File 'lib/para_dice/bag.rb', line 15

attribute :dice, Hash[String => Die], default: {}

#nameString

Returns default: ‘Dice Bag’.

Returns:

  • (String)

    default: ‘Dice Bag’



12
# File 'lib/para_dice/bag.rb', line 12

attribute :name, String, default: 'Dice Bag'

#rngRandom

Returns default: Random.new.

Returns:

  • (Random)

    default: Random.new



21
# File 'lib/para_dice/bag.rb', line 21

attribute :rng, Random, default: ->(*a) { Random.new }

Instance Method Details

#add_die(die) ⇒ Object

add a die to the bag

Parameters:



25
26
27
# File 'lib/para_dice/bag.rb', line 25

def add_die(die)
  dice[die.name] = die
end

#get_cup(*dice_names) ⇒ Object

given an array of dice_names, create a Cup using them and default_readers @param(*dice_names) array of dice names.



37
38
39
40
41
42
# File 'lib/para_dice/bag.rb', line 37

def get_cup(*dice_names)
  Cup.new(dice:    get_dice(*dice_names),
          rng:     rng,
          readers: default_readers
  )
end

#get_dice(*dice_names) ⇒ Object

get an array of dice from an array of dice names @param(*dice_names) array of dice names.



31
32
33
# File 'lib/para_dice/bag.rb', line 31

def get_dice(*dice_names)
  dice_names.flatten.map { |die_name| dice[die_name.to_s] }
end