Class: Randsum::Replacer
- Inherits:
-
Object
- Object
- Randsum::Replacer
- Defined in:
- lib/randsum/filters/replacers/replacer.rb
Instance Attribute Summary collapse
-
#roll ⇒ Object
readonly
Returns the value of attribute roll.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#with ⇒ Object
readonly
Returns the value of attribute with.
Class Method Summary collapse
Instance Method Summary collapse
- #filter ⇒ Object
-
#initialize(target:, with:, roll:) ⇒ Replacer
constructor
A new instance of Replacer.
- #result ⇒ Object
- #transformed ⇒ Object
Constructor Details
#initialize(target:, with:, roll:) ⇒ Replacer
Returns a new instance of Replacer.
13 14 15 16 17 |
# File 'lib/randsum/filters/replacers/replacer.rb', line 13 def initialize(target:, with:, roll:) @target = ReplacerTarget.for(target, roll: roll) @with = ReplacerValue.for(with, roll: roll) @roll = roll end |
Instance Attribute Details
#roll ⇒ Object (readonly)
Returns the value of attribute roll.
3 4 5 |
# File 'lib/randsum/filters/replacers/replacer.rb', line 3 def roll @roll end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
3 4 5 |
# File 'lib/randsum/filters/replacers/replacer.rb', line 3 def target @target end |
#with ⇒ Object (readonly)
Returns the value of attribute with.
3 4 5 |
# File 'lib/randsum/filters/replacers/replacer.rb', line 3 def with @with end |
Class Method Details
.for(target:, with:, roll:) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/randsum/filters/replacers/replacer.rb', line 5 def self.for(target:, with:, roll:) Randsum::Replacer.new( target: target, with: with, roll: roll, ) end |
Instance Method Details
#filter ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/randsum/filters/replacers/replacer.rb', line 19 def filter return Randsum::Roll.new( die: roll.die, quantity: roll.quantity, result: result ) end |
#result ⇒ Object
27 28 29 |
# File 'lib/randsum/filters/replacers/replacer.rb', line 27 def result (roll.result - target.match) + transformed end |
#transformed ⇒ Object
31 32 33 |
# File 'lib/randsum/filters/replacers/replacer.rb', line 31 def transformed with.transform(target.match) end |