Class: FifthedSim::DiceExpression
- Inherits:
-
Object
- Object
- FifthedSim::DiceExpression
show all
- Defined in:
- lib/fifthed_sim/dice_expression.rb
Overview
This is an abstract dice expression class
Instance Method Summary
collapse
Instance Method Details
#*(other) ⇒ Object
32
33
34
|
# File 'lib/fifthed_sim/dice_expression.rb', line 32
def *(other)
MultiplicationNode.new(self, other.to_dice_expression)
end
|
#+(other) ⇒ Object
20
21
22
|
# File 'lib/fifthed_sim/dice_expression.rb', line 20
def +(other)
AdditionNode.new(self, other.to_dice_expression)
end
|
#-(other) ⇒ Object
24
25
26
|
# File 'lib/fifthed_sim/dice_expression.rb', line 24
def -(other)
SubtractionNode.new(self, other.to_dice_expression)
end
|
#/(other) ⇒ Object
28
29
30
|
# File 'lib/fifthed_sim/dice_expression.rb', line 28
def /(other)
DivisionNode.new(self, other.to_dice_expression)
end
|
#average ⇒ Object
16
17
18
|
# File 'lib/fifthed_sim/dice_expression.rb', line 16
def average
distribution.average
end
|
#difference_from_average ⇒ Object
Get this difference of the average value and the current value. For example, if the average is 10 and we have a value of 20, it will return 10. Meanwhile, if the average is 10 and we have a value of 2, it will return -8.
73
74
75
|
# File 'lib/fifthed_sim/dice_expression.rb', line 73
def difference_from_average
value - average
end
|
#max ⇒ Object
48
49
50
|
# File 'lib/fifthed_sim/dice_expression.rb', line 48
def max
distribution.max
end
|
#min ⇒ Object
52
53
54
|
# File 'lib/fifthed_sim/dice_expression.rb', line 52
def min
distribution.min
end
|
#or_greater(other) ⇒ Object
36
37
38
|
# File 'lib/fifthed_sim/dice_expression.rb', line 36
def or_greater(other)
GreaterNode.new(self, other.to_dice_expression)
end
|
#or_least(other) ⇒ Object
40
41
42
|
# File 'lib/fifthed_sim/dice_expression.rb', line 40
def or_least(other)
LessNode.new(self, other.to_dice_expression)
end
|
#percentile ⇒ Object
44
45
46
|
# File 'lib/fifthed_sim/dice_expression.rb', line 44
def percentile
distribution.percent_lower_equal(value)
end
|
#range ⇒ Object
77
78
79
|
# File 'lib/fifthed_sim/dice_expression.rb', line 77
def range
(min..max)
end
|
#test_then(&block) ⇒ Object
Takes a block, which should take a single argument This block should return another DiceExpression type, based on the result of this DiceExpression.
59
60
61
|
# File 'lib/fifthed_sim/dice_expression.rb', line 59
def test_then(&block)
BlockNode.new(self, &block)
end
|
#to_dice_expression ⇒ Object
81
82
83
|
# File 'lib/fifthed_sim/dice_expression.rb', line 81
def to_dice_expression
self.dup
end
|
#to_f ⇒ Object
12
13
14
|
# File 'lib/fifthed_sim/dice_expression.rb', line 12
def to_f
value.to_f
end
|
#to_i ⇒ Object
8
9
10
|
# File 'lib/fifthed_sim/dice_expression.rb', line 8
def to_i
value
end
|