Module: DiceBag

Defined in:
lib/dicebag.rb,
lib/dicebag/roll.rb,
lib/dicebag/parser.rb,
lib/dicebag/result.rb,
lib/dicebag/normalize.rb,
lib/dicebag/roll_part.rb,
lib/dicebag/transform.rb,
lib/dicebag/label_part.rb,
lib/dicebag/simple_part.rb,
lib/dicebag/static_part.rb,
lib/dicebag/min_max_calc.rb

Overview

DiceBag module

Defined Under Namespace

Classes: DiceBagError, LabelPart, MinMaxCalc, Normalize, Parser, Result, Roll, RollPart, SimplePart, StaticPart, Transform

Class Method Summary collapse

Class Method Details

.average(dstr) ⇒ Object



26
27
28
# File 'lib/dicebag.rb', line 26

def self.average(dstr)
  DiceBag::Roll.new(dstr).average
end

.default_rollObject

The default roll if one is not given.



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

def self.default_roll
  '1d6'
end

.maximum(dstr) ⇒ Object



30
31
32
# File 'lib/dicebag.rb', line 30

def self.maximum(dstr)
  DiceBag::Roll.new(dstr).maximum
end

.minimum(dstr) ⇒ Object



34
35
36
# File 'lib/dicebag.rb', line 34

def self.minimum(dstr)
  DiceBag::Roll.new(dstr).minimum
end

.parse(dstr = '') ⇒ Object

This is the wrapper for the parse, transform, and normalize calls. This is called by the Roll class, but may be called to get the raw returned array of parsed parts for other purposes.



11
12
13
14
15
16
# File 'lib/dicebag.rb', line 11

def self.parse(dstr = '')
  tree = Parser.new.parse(dstr)
  ast  = Transform.new.apply(tree)

  Normalize.call ast
end

.roll(dstr) ⇒ Object

Main Syntatic Sugar Interface Methodds



22
23
24
# File 'lib/dicebag.rb', line 22

def self.roll(dstr)
  DiceBag::Roll.new(dstr).roll
end