Class: BagOfHolding::Dice::Transform
- Inherits:
-
Parslet::Transform
- Object
- Parslet::Transform
- BagOfHolding::Dice::Transform
- Defined in:
- lib/bag_of_holding/dice/transform.rb
Overview
Internal: Transform a parsed dice string into a callable structure
Class Method Summary collapse
- .build_const(value:) ⇒ Object
- .build_operation(left:, operator:, right:) ⇒ Object
- .build_pool(count: nil, die:, label: nil) ⇒ Object
Class Method Details
.build_const(value:) ⇒ Object
48 49 50 |
# File 'lib/bag_of_holding/dice/transform.rb', line 48 def self.build_const(value:) BagOfHolding::Dice::Constant.new value: Integer(value) end |
.build_operation(left:, operator:, right:) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/bag_of_holding/dice/transform.rb', line 38 def self.build_operation(left:, operator:, right:) operations = [ AdditionOperation, SubtractionOperation, DivisionOperation, MultiplicationOperation ] operations.find { |o| o.operator == operator }.new left: left, right: right end |
.build_pool(count: nil, die:, label: nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/bag_of_holding/dice/transform.rb', line 52 def self.build_pool(count: nil, die:, label: nil) BagOfHolding::Dice::PoolFactory.build count: count, die: die, label: label end |