Module: Lorca::LorcaCore::LorcaPlugin
- Defined in:
- lib/lorca.rb
Overview
LorcaCore instance methods.
Instance Method Summary collapse
-
#roll_dice ⇒ Object
Roll a six-sided dice.
-
#roll_word_id(dice:) ⇒ Object
Roll a word id using given number of
dice
. -
#settings ⇒ Object
Lorca instance settings hash.
-
#validate_counter(number, range:) ⇒ Object
Validate a given counter
number
is within the givenrange
. -
#validate_positive_integer(counter) ⇒ Object
Validate
counter
is a number greater than zero. -
#validate_range(range) ⇒ Object
Validate the
range
given is end-inclusive, and only positive numbers.
Instance Method Details
#roll_dice ⇒ Object
Roll a six-sided dice.
78 79 80 |
# File 'lib/lorca.rb', line 78 def roll_dice (SecureRandom.random_number(5) + 1) end |
#roll_word_id(dice:) ⇒ Object
Roll a word id using given number of dice
.
68 69 70 71 72 73 74 75 |
# File 'lib/lorca.rb', line 68 def roll_word_id(dice:) dice = validate_counter dice, range: dice..dice id = "" dice.times { id += roll_dice.to_s } id rescue Lorca::LorcaCounterError => e raise Lorca::LorcaDiceError, e. end |
#settings ⇒ Object
Lorca instance settings hash. Frozen duplicate of class settings meant for reading expansion configurations.
63 64 65 |
# File 'lib/lorca.rb', line 63 def settings self.class.settings.dup.freeze end |
#validate_counter(number, range:) ⇒ Object
Validate a given counter number
is within the given range
.
83 84 85 86 87 88 89 |
# File 'lib/lorca.rb', line 83 def validate_counter(number, range:) num = validate_positive_integer number return num if num == range.min && num == range.max range = validate_range range range.cover?(num) ? num : fail(LorcaCounterError, "Counter out of range") end |
#validate_positive_integer(counter) ⇒ Object
Validate counter
is a number greater than zero.
101 102 103 104 105 106 |
# File 'lib/lorca.rb', line 101 def validate_positive_integer counter unless counter.is_a?(Integer) && counter > 0 fail LorcaCounterError, "Should be a positive integer" end counter end |
#validate_range(range) ⇒ Object
Validate the range
given is end-inclusive, and only positive numbers.
92 93 94 95 96 97 98 |
# File 'lib/lorca.rb', line 92 def validate_range range validate_positive_integer range.min validate_positive_integer range.max range rescue Lorca::LorcaCounterError raise LorcaRangeError, "Should be an end-inclusive range of positive integers" end |