Class: Dicey::CLI::CalculatorRunner Private
- Inherits:
-
Object
- Object
- Dicey::CLI::CalculatorRunner
- Defined in:
- lib/dicey/cli/calculator_runner.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The defaultest runner which calculates roll distribution from command-line dice.
Instance Method Summary collapse
-
#call(arguments, format:, result:) ⇒ String
private
Transform die definitions to roll distribution.
Instance Method Details
#call(arguments, format:, result:) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Transform die definitions to roll distribution.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dicey/cli/calculator_runner.rb', line 18 def call(arguments, format:, result:, **) raise DiceyError, "no dice!" if arguments.empty? dice = arguments.flat_map { |definition| die_foundry.cast(definition) } calculator = DistributionCalculators::AutoSelector.call(dice) raise DiceyError, "no calculator could handle these dice!" unless calculator distribution = calculator.call(dice, result_type: result) format.call(distribution, AbstractDie.describe(dice)) end |