nerd_dice 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +31 -2
- data/Gemfile.lock +22 -20
- data/README.md +50 -4
- data/checksum/nerd_dice-0.1.1.gem.sha256 +1 -0
- data/checksum/nerd_dice-0.1.1.gem.sha512 +1 -0
- data/lib/nerd_dice.rb +148 -19
- data/lib/nerd_dice/configuration.rb +47 -0
- data/lib/nerd_dice/version.rb +1 -1
- data/nerd_dice.gemspec +5 -2
- metadata +34 -11
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a931b4532dcafcb4ce3aeddf3ac30399bb9334d25bf78671a0811366670d719
|
4
|
+
data.tar.gz: 970d96a32b68dc1fc75618376bf059707c5c711441d30edd6302dcd37e831c8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cdbd36e786d2c4e6f8950f4486119548bb1a62babdbf3c9ae4fadba095170b9300461411926d19ca50e5e8d277804c3f8cb61e28d96605fd5fad8b7e9c9b700
|
7
|
+
data.tar.gz: 21b2b92dbf7ad4060a888d267383e9c87b3e310dff4931bb1853f401fb417f480a2bea7cca859ad75d3eac83608a4631541a36afc7449955a68ea8ff84c319c7
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.rubocop.yml
CHANGED
@@ -313,3 +313,24 @@ Performance/StringInclude: # (new in 1.7)
|
|
313
313
|
|
314
314
|
Performance/Sum: # (new in 1.8)
|
315
315
|
Enabled: true
|
316
|
+
|
317
|
+
Layout/SpaceBeforeBrackets: # (new in 1.7)
|
318
|
+
Enabled: true
|
319
|
+
|
320
|
+
Lint/AmbiguousAssignment: # (new in 1.7)
|
321
|
+
Enabled: true
|
322
|
+
|
323
|
+
Lint/DeprecatedConstants: # (new in 1.8)
|
324
|
+
Enabled: true
|
325
|
+
|
326
|
+
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
|
327
|
+
Enabled: true
|
328
|
+
|
329
|
+
Lint/RedundantDirGlobSort: # (new in 1.8)
|
330
|
+
Enabled: true
|
331
|
+
|
332
|
+
Style/EndlessMethod: # (new in 1.8)
|
333
|
+
Enabled: true
|
334
|
+
|
335
|
+
Style/HashExcept: # (new in 1.7)
|
336
|
+
Enabled: true
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,42 @@
|
|
1
1
|
# Nerd Dice Changelog
|
2
2
|
|
3
3
|
## master \(unreleased\)
|
4
|
+
### Added
|
5
|
+
### Changed
|
6
|
+
### Fixed
|
7
|
+
|
8
|
+
## 0.2.0 \(2020-12-12\)
|
9
|
+
### Added
|
10
|
+
* Add ability to configure with `NerdDice.configure` block or `NerdDice.configuration`
|
11
|
+
- Configure `randomization_technique` as `:random_rand`, `:securerandom`, `:random_object`, or `randomized`
|
12
|
+
- Configure `refresh_seed_interval` to allow a periodic refresh of the seed
|
13
|
+
* Add `randomization_technique` option to `NerdDice.total_dice` method keyword arguments
|
14
|
+
* Add a lower-level `execute_die_roll` method that allows you to roll a single die with a generator specified
|
15
|
+
* Add ability to manually refresh or specify seed with `:refresh_seed!` method
|
16
|
+
### Changed
|
17
|
+
* Change `opts = {}` final argument to use keyword args `**opts` in the `NerdDice.total_dice` method. Now the method can be called as follows:
|
18
|
+
```ruby
|
19
|
+
# old
|
20
|
+
NerdDice.total_dice(20, 1, {bonus: 5})
|
21
|
+
NerdDice.total_dice(6, 3, {bonus: 1})
|
22
|
+
|
23
|
+
# new
|
24
|
+
NerdDice.total_dice(20, bonus: 5)
|
25
|
+
NerdDice.total_dice(6, 3, bonus: 1)
|
26
|
+
```
|
27
|
+
* Call `:to_i` on bonus instead of using `:is_a?` and raise ArgumentError in the `NerdDice.total_dice` method if it doesn't respond to `:to_i`
|
28
|
+
* Added `securerandom` as an explicit dependency due to Ruby 3.x change to bundled gem
|
29
|
+
* `total_dice` no longer calls unqualified `.rand` which improves performance on all generators except for `:securerandom`
|
30
|
+
### Fixed
|
4
31
|
|
5
32
|
## 0.1.1 \(2020-12-12\)
|
6
|
-
###
|
33
|
+
### Added
|
34
|
+
### Changed
|
35
|
+
### Fixed
|
7
36
|
* Fix broken link to CHANGELOG in gemspec
|
8
37
|
* Fix rubocop offenses from 0.1.0 and refactor specs
|
9
38
|
|
10
39
|
## 0.1.0 \(2020-12-07\)
|
11
40
|
|
12
|
-
###
|
41
|
+
### Added
|
13
42
|
* Add NerdDice.total_dice class method with the ability to roll multiple polyhedral dice and add a bonus
|
data/Gemfile.lock
CHANGED
@@ -1,54 +1,56 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nerd_dice (0.
|
4
|
+
nerd_dice (0.2.0)
|
5
|
+
securerandom (~> 0.1, >= 0.1.0)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
9
|
-
ast (2.4.
|
10
|
+
ast (2.4.2)
|
10
11
|
diff-lcs (1.4.4)
|
11
12
|
parallel (1.20.1)
|
12
|
-
parser (
|
13
|
+
parser (3.0.0.0)
|
13
14
|
ast (~> 2.4.1)
|
14
15
|
rainbow (3.0.0)
|
15
16
|
rake (12.3.3)
|
16
|
-
regexp_parser (
|
17
|
-
rexml (3.2.
|
17
|
+
regexp_parser (2.0.3)
|
18
|
+
rexml (3.2.4)
|
18
19
|
rspec (3.10.0)
|
19
20
|
rspec-core (~> 3.10.0)
|
20
21
|
rspec-expectations (~> 3.10.0)
|
21
22
|
rspec-mocks (~> 3.10.0)
|
22
|
-
rspec-core (3.10.
|
23
|
+
rspec-core (3.10.1)
|
23
24
|
rspec-support (~> 3.10.0)
|
24
|
-
rspec-expectations (3.10.
|
25
|
+
rspec-expectations (3.10.1)
|
25
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
26
27
|
rspec-support (~> 3.10.0)
|
27
|
-
rspec-mocks (3.10.
|
28
|
+
rspec-mocks (3.10.1)
|
28
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
29
30
|
rspec-support (~> 3.10.0)
|
30
|
-
rspec-support (3.10.
|
31
|
-
rubocop (1.
|
31
|
+
rspec-support (3.10.1)
|
32
|
+
rubocop (1.8.1)
|
32
33
|
parallel (~> 1.10)
|
33
|
-
parser (>=
|
34
|
+
parser (>= 3.0.0.0)
|
34
35
|
rainbow (>= 2.2.2, < 4.0)
|
35
36
|
regexp_parser (>= 1.8, < 3.0)
|
36
37
|
rexml
|
37
38
|
rubocop-ast (>= 1.2.0, < 2.0)
|
38
39
|
ruby-progressbar (~> 1.7)
|
39
|
-
unicode-display_width (>= 1.4.0, <
|
40
|
-
rubocop-ast (1.
|
40
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
41
|
+
rubocop-ast (1.4.1)
|
41
42
|
parser (>= 2.7.1.5)
|
42
|
-
rubocop-performance (1.9.
|
43
|
+
rubocop-performance (1.9.2)
|
43
44
|
rubocop (>= 0.90.0, < 2.0)
|
44
45
|
rubocop-ast (>= 0.4.0)
|
45
46
|
rubocop-rake (0.5.1)
|
46
47
|
rubocop
|
47
|
-
rubocop-rspec (2.0
|
48
|
+
rubocop-rspec (2.1.0)
|
48
49
|
rubocop (~> 1.0)
|
49
50
|
rubocop-ast (>= 1.1.0)
|
50
|
-
ruby-progressbar (1.
|
51
|
-
|
51
|
+
ruby-progressbar (1.11.0)
|
52
|
+
securerandom (0.1.0)
|
53
|
+
unicode-display_width (2.0.0)
|
52
54
|
|
53
55
|
PLATFORMS
|
54
56
|
ruby
|
@@ -57,10 +59,10 @@ DEPENDENCIES
|
|
57
59
|
nerd_dice!
|
58
60
|
rake (~> 12.0)
|
59
61
|
rspec (~> 3.0)
|
60
|
-
rubocop (~> 1.
|
62
|
+
rubocop (~> 1.8, >= 1.8.1)
|
61
63
|
rubocop-performance (~> 1.9, >= 1.9.1)
|
62
64
|
rubocop-rake (~> 0.5, >= 0.5.1)
|
63
|
-
rubocop-rspec (~> 2.
|
65
|
+
rubocop-rspec (~> 2.1, >= 2.1.0)
|
64
66
|
|
65
67
|
BUNDLED WITH
|
66
|
-
2.
|
68
|
+
2.2.3
|
data/README.md
CHANGED
@@ -18,18 +18,64 @@ Or install it yourself as:
|
|
18
18
|
$ gem install nerd_dice
|
19
19
|
|
20
20
|
## Usage
|
21
|
+
### Configuration
|
22
|
+
You can customize the behavior of NerdDice via a configuration block as below or by assigning an individual property via the ```NerdDice.configuration.property = value``` syntax \(where ```property``` is the config property and ```value``` is the value you want to assign\)\. The available configuration options as well as their defaults, if applicable, are listed in the example configuration block below:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
NerdDice.configure do | config|
|
26
|
+
|
27
|
+
# number of ability scores to place in an ability score array
|
28
|
+
config.ability_score_array_size = 6
|
29
|
+
|
30
|
+
# randomization technique options are:
|
31
|
+
# :securerandom => Uses SecureRandom.rand(). Good entropy, medium speed.
|
32
|
+
# :random_rand => Uses Random.rand(). Class method. Poor entropy, fastest speed.
|
33
|
+
# (Seed is shared with other processes. Too predictable)
|
34
|
+
# :random_object => Uses Random.new() and calls rand()
|
35
|
+
# Medium entropy, fastest speed. (Performs the best under speed benchmark)
|
36
|
+
# :randomized => Uses a random choice of the :securerandom, :rand, and :random_new_interval options above
|
37
|
+
config.randomization_technique = :random_object # fast with independent seed
|
38
|
+
|
39
|
+
# Number of iterations to use on a generator before refreshing the seed
|
40
|
+
# 1 very slow and heavy pressure on processor and memory but very high entropy
|
41
|
+
# 1000 would refresh the object every 1000 times you call rand()
|
42
|
+
config.refresh_seed_interval = nil # don't refresh the seed
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
21
46
|
### Rolling a number of dice and adding a bonus
|
22
47
|
```ruby
|
23
48
|
# roll a single d4
|
24
49
|
NerdDice.total_dice(4) # => return random Integer between 1-4
|
25
50
|
|
26
51
|
# roll 3d6
|
27
|
-
NerdDice.total_dice(6, 3) => return Integer total of three 6-sided dice
|
52
|
+
NerdDice.total_dice(6, 3) # => return Integer total of three 6-sided dice
|
28
53
|
|
29
54
|
# roll a d20 and add 5 to the value
|
30
|
-
NerdDice.total_dice(20,
|
55
|
+
NerdDice.total_dice(20, bonus: 5)
|
56
|
+
|
57
|
+
# roll a d20 and overide the configured randomization_technique one time
|
58
|
+
# without changing the config
|
59
|
+
NerdDice.total_dice(20, randomization_technique: :randomized)
|
60
|
+
```
|
61
|
+
__NOTE:__ If provided, the bonus must respond to `:to_i` or an `ArgumentError` will be raised
|
62
|
+
|
63
|
+
### Manually setting or refreshing the random generator seed
|
64
|
+
For randomization techniques other than `:securerandom` you can manually set or refresh the generator's seed by calling the `refresh_seed!` method. This is automatically called at the interval specified in `NerdDice.configuration.refresh_seed_interval` if it is not nil.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# no arguments, will refresh the seed for the configured generator(s) only
|
68
|
+
NerdDice.refresh_seed! # => hash with old seed(s) or nil if :securerandom
|
69
|
+
|
70
|
+
# OPTIONS:
|
71
|
+
# randomization_technique (Symbol) => NerdDice::RANDOMIZATION_TECHNIQUES
|
72
|
+
# random_rand_seed (Integer) => Seed to set for Random
|
73
|
+
# random_object_seed (Integer) => Seed to set for new Random object
|
74
|
+
NerdDice.refresh_seed!(randomization_technique: :randomized,
|
75
|
+
random_rand_seed: 1337,
|
76
|
+
random_object_seed: 24601)
|
31
77
|
```
|
32
|
-
__NOTE:__
|
78
|
+
__NOTE:__ Ability to specify a seed it primarily provided for testing purposes. This makes all random numbers generated _transparently deterministic_ and should not be used if you want behavior approximating randomness.
|
33
79
|
|
34
80
|
## Development
|
35
81
|
|
@@ -44,4 +90,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/statel
|
|
44
90
|
|
45
91
|
## Unlicense, License, and Copyright
|
46
92
|
|
47
|
-
The document is dual-licensed under the [MIT](https://opensource.org/licenses/MIT) license and the [UNLICENSE](https://unlicense.org/) \(with strong preference toward the UNLICENSE\)\. The content is released under [CC0](https://creativecommons.org/share-your-work/public-domain/cc0/) \(no rights reserved\). You are free to include it in its original form or modified with or without modification in your own project\.
|
93
|
+
The document is dual-licensed under the [MIT](https://opensource.org/licenses/MIT) license and the [UNLICENSE](https://unlicense.org/) \(with strong preference toward the UNLICENSE\)\. The content is released under [CC0](https://creativecommons.org/share-your-work/public-domain/cc0/) \(no rights reserved\). You are free to include it in its original form or modified with or without modification in your own project\.
|
@@ -0,0 +1 @@
|
|
1
|
+
3b8e94b12954afbeb9c08746c57a19e06dc2405cb0e74f500d0111ef99e97f72
|
@@ -0,0 +1 @@
|
|
1
|
+
469f2104263dbf07ab0e83e04a3b08087b3f64a7702143ed2387a04601c7db2c0e43404dd325de1d2fbe394858973e6d9bb214d9b0f602cead65b7dc4fbcb46b
|
data/lib/nerd_dice.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "nerd_dice/version"
|
4
|
+
require "nerd_dice/configuration"
|
5
|
+
require "securerandom"
|
4
6
|
# Nerd dice allows you to roll polyhedral dice and add bonuses as you would in
|
5
7
|
# a tabletop roleplaying game. You can choose to roll multiple dice and keep a
|
6
8
|
# specified number of dice such as rolling 4d6 and dropping the lowest for
|
@@ -23,25 +25,152 @@ require "nerd_dice/version"
|
|
23
25
|
module NerdDice
|
24
26
|
class Error < StandardError; end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
28
|
+
RANDOMIZATION_TECHNIQUES = %i[securerandom random_rand random_object randomized].freeze
|
29
|
+
|
30
|
+
class << self
|
31
|
+
attr_reader :count_since_last_refresh
|
32
|
+
|
33
|
+
############################
|
34
|
+
# configure class method
|
35
|
+
############################
|
36
|
+
# Arguments: None
|
37
|
+
# Expects and yields to a block where configuration is specified.
|
38
|
+
# See README and NerdDice::Configuration class for config options
|
39
|
+
# Return (NerdDice::Configuration) the Configuration object tied to the
|
40
|
+
# @configuration class instance variable
|
41
|
+
def configure
|
42
|
+
yield configuration
|
43
|
+
configuration
|
44
|
+
end
|
45
|
+
|
46
|
+
############################
|
47
|
+
# configuration class method
|
48
|
+
############################
|
49
|
+
# Arguments: None
|
50
|
+
# Provides the lazy-loaded class instance variable @configuration
|
51
|
+
# Return (NerdDice::Configuration) the Configuration object tied to the
|
52
|
+
# @configuration class instance variable
|
53
|
+
def configuration
|
54
|
+
@configuration ||= Configuration.new
|
55
|
+
end
|
56
|
+
|
57
|
+
############################
|
58
|
+
# total_dice class method
|
59
|
+
############################
|
60
|
+
# Arguments:
|
61
|
+
# number_of_sides (Integer) => the number of sides of the dice to roll
|
62
|
+
# number_of_dice (Integer, DEFAULT: 1) => the quantity to roll of the type
|
63
|
+
# of die specified in the number_of_sides argument.
|
64
|
+
# options (Hash, DEFAULT: {}) any additional options you wish to include
|
65
|
+
# :bonus (Integer) => The total bonus (positive integer) or penalty
|
66
|
+
# (negative integer) to modify the total by. Is added to the total of
|
67
|
+
# all dice after they are totaled, not to each die rolled
|
68
|
+
#
|
69
|
+
# Return (Integer) => Total of the dice rolled, plus modifier if applicable
|
70
|
+
def total_dice(number_of_sides, number_of_dice = 1, **opts)
|
71
|
+
total = 0
|
72
|
+
number_of_dice.times do
|
73
|
+
total += execute_die_roll(number_of_sides, opts[:randomization_technique])
|
74
|
+
end
|
75
|
+
begin
|
76
|
+
total += opts[:bonus].to_i
|
77
|
+
rescue NoMethodError
|
78
|
+
raise ArgumentError, "Bonus must be a value that responds to :to_i"
|
79
|
+
end
|
80
|
+
total
|
81
|
+
end
|
82
|
+
|
83
|
+
############################
|
84
|
+
# execute_die_roll class method
|
85
|
+
############################
|
86
|
+
# Arguments:
|
87
|
+
# number_of_sides (Integer) => the number of sides of the die to roll
|
88
|
+
# using_generator (Symbol) => must be one of the symbols in
|
89
|
+
# RANDOMIZATION_TECHNIQUES or nil
|
90
|
+
#
|
91
|
+
# Return (Integer) => Value of the single die rolled
|
92
|
+
def execute_die_roll(number_of_sides, using_generator = nil)
|
93
|
+
@count_since_last_refresh ||= 0
|
94
|
+
gen = get_number_generator(using_generator)
|
95
|
+
result = gen.rand(number_of_sides) + 1
|
96
|
+
increment_and_evalutate_refresh_seed
|
97
|
+
result
|
98
|
+
end
|
99
|
+
|
100
|
+
############################
|
101
|
+
# refresh_seed! class method
|
102
|
+
############################
|
103
|
+
# Options: (none required)
|
104
|
+
# randomization_technique (Symbol) => must be one of the symbols in
|
105
|
+
# RANDOMIZATION_TECHNIQUES if specified
|
106
|
+
# random_rand_seed (Integer) => Seed to set for Random
|
107
|
+
# random_object_seed (Integer) => Seed to set for new Random object
|
108
|
+
# Return (Hash or nil) => Previous values of generator seeds that were refreshed
|
109
|
+
def refresh_seed!(**opts)
|
110
|
+
technique, random_rand_new_seed, random_object_new_seed = parse_refresh_options(opts)
|
111
|
+
@count_since_last_refresh = 0
|
112
|
+
return nil if technique == :securerandom
|
113
|
+
|
114
|
+
reset_appropriate_seeds!(technique, random_rand_new_seed, random_object_new_seed)
|
43
115
|
end
|
44
|
-
|
45
|
-
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def get_number_generator(using_generator = nil)
|
120
|
+
using_generator ||= configuration.randomization_technique
|
121
|
+
case using_generator
|
122
|
+
when :securerandom then SecureRandom
|
123
|
+
when :random_rand then Random
|
124
|
+
when :random_object then @random_object ||= Random.new
|
125
|
+
when :randomized then random_generator
|
126
|
+
else raise ArgumentError, "Unrecognized generator. Must be one of #{RANDOMIZATION_TECHNIQUES.join(', ')}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def random_generator
|
131
|
+
gen = RANDOMIZATION_TECHNIQUES.reject { |el| el == :randomized }.sample
|
132
|
+
get_number_generator(gen)
|
133
|
+
end
|
134
|
+
|
135
|
+
def refresh_random_rand_seed!(new_seed)
|
136
|
+
new_seed ? Random.srand(new_seed) : Random.srand
|
137
|
+
end
|
138
|
+
|
139
|
+
def refresh_random_object_seed!(new_seed)
|
140
|
+
old_seed = @random_object&.seed
|
141
|
+
@random_object = new_seed ? Random.new(new_seed) : Random.new
|
142
|
+
old_seed
|
143
|
+
end
|
144
|
+
|
145
|
+
def parse_refresh_options(opts)
|
146
|
+
[
|
147
|
+
opts[:randomization_technique] || configuration.randomization_technique,
|
148
|
+
opts[:random_rand_seed],
|
149
|
+
opts[:random_object_seed]
|
150
|
+
]
|
151
|
+
end
|
152
|
+
|
153
|
+
# rubocop:disable Metrics/MethodLength
|
154
|
+
def reset_appropriate_seeds!(technique, random_rand_new_seed, random_object_new_seed)
|
155
|
+
return_hash = {}
|
156
|
+
case technique
|
157
|
+
when :random_rand
|
158
|
+
return_hash[:random_rand_prior_seed] = refresh_random_rand_seed!(random_rand_new_seed)
|
159
|
+
when :random_object
|
160
|
+
return_hash[:random_object_prior_seed] = refresh_random_object_seed!(random_object_new_seed)
|
161
|
+
when :randomized
|
162
|
+
return_hash[:random_rand_prior_seed] = refresh_random_rand_seed!(random_rand_new_seed)
|
163
|
+
return_hash[:random_object_prior_seed] = refresh_random_object_seed!(random_object_new_seed)
|
164
|
+
end
|
165
|
+
return_hash
|
166
|
+
end
|
167
|
+
# rubocop:enable Metrics/MethodLength
|
168
|
+
|
169
|
+
def increment_and_evalutate_refresh_seed
|
170
|
+
@count_since_last_refresh += 1
|
171
|
+
return unless configuration.refresh_seed_interval
|
172
|
+
|
173
|
+
refresh_seed! if @count_since_last_refresh >= configuration.refresh_seed_interval
|
174
|
+
end
|
46
175
|
end
|
47
176
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NerdDice
|
4
|
+
# The NerdDice::Configuration class allows you to configure and customize the
|
5
|
+
# options of the NerdDice gem to suit your specific needs. You can specify
|
6
|
+
# properties like the randomization technique used by the gem, the number of
|
7
|
+
# ability scores in an ability score array, etc. See the README for a list of
|
8
|
+
# configurable attributes.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
# The configuration can either be set via a configure block:
|
12
|
+
# <tt>NerdDice.configure do |config|
|
13
|
+
# config.randomization_technique = :random_new_interval
|
14
|
+
# config.new_random_interval = 100
|
15
|
+
# end
|
16
|
+
# </tt>
|
17
|
+
#
|
18
|
+
# You can also set a particular property without a block using inline assignment
|
19
|
+
# <tt>NerdDice.configuration.randomization_technique = :random_new_once</tt>
|
20
|
+
class Configuration
|
21
|
+
attr_reader :randomization_technique, :refresh_seed_interval
|
22
|
+
attr_accessor :ability_score_array_size
|
23
|
+
|
24
|
+
def randomization_technique=(value)
|
25
|
+
unless RANDOMIZATION_TECHNIQUES.include?(value)
|
26
|
+
raise NerdDice::Error, "randomization_technique must be one of #{RANDOMIZATION_TECHNIQUES.join(', ')}"
|
27
|
+
end
|
28
|
+
|
29
|
+
@randomization_technique = value
|
30
|
+
end
|
31
|
+
|
32
|
+
def refresh_seed_interval=(value)
|
33
|
+
unless value.nil?
|
34
|
+
value = value&.to_i
|
35
|
+
raise NerdDice::Error, "refresh_seed_interval must be a positive integer or nil" unless value.positive?
|
36
|
+
end
|
37
|
+
@refresh_seed_interval = value
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def initialize
|
43
|
+
@ability_score_array_size = 6
|
44
|
+
@randomization_technique = :random_object
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/nerd_dice/version.rb
CHANGED
data/nerd_dice.gemspec
CHANGED
@@ -43,8 +43,11 @@ Gem::Specification.new do |spec|
|
|
43
43
|
spec.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $PROGRAM_NAME.end_with?("gem")
|
44
44
|
|
45
45
|
# Dependencies
|
46
|
-
spec.
|
46
|
+
spec.add_dependency "securerandom", "~> 0.1", ">= 0.1.0"
|
47
|
+
|
48
|
+
# Development Dependencies
|
49
|
+
spec.add_development_dependency "rubocop", "~> 1.8", ">= 1.8.1"
|
47
50
|
spec.add_development_dependency "rubocop-performance", "~> 1.9", ">= 1.9.1"
|
48
51
|
spec.add_development_dependency "rubocop-rake", "~> 0.5", ">= 0.5.1"
|
49
|
-
spec.add_development_dependency "rubocop-rspec", "~> 2.
|
52
|
+
spec.add_development_dependency "rubocop-rspec", "~> 2.1", ">= 2.1.0"
|
50
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nerd_dice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Duchemin
|
@@ -35,28 +35,48 @@ cert_chain:
|
|
35
35
|
WQ4faXJSevxT+x9TgyUNJINPkz/KqreClzdL83cwxPzFFQto7zF6zMCsj0slqJjW
|
36
36
|
EQ==
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2021-01-28 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: securerandom
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.1'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.1.0
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0.1'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.1.0
|
40
60
|
- !ruby/object:Gem::Dependency
|
41
61
|
name: rubocop
|
42
62
|
requirement: !ruby/object:Gem::Requirement
|
43
63
|
requirements:
|
44
64
|
- - "~>"
|
45
65
|
- !ruby/object:Gem::Version
|
46
|
-
version: '1.
|
66
|
+
version: '1.8'
|
47
67
|
- - ">="
|
48
68
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.
|
69
|
+
version: 1.8.1
|
50
70
|
type: :development
|
51
71
|
prerelease: false
|
52
72
|
version_requirements: !ruby/object:Gem::Requirement
|
53
73
|
requirements:
|
54
74
|
- - "~>"
|
55
75
|
- !ruby/object:Gem::Version
|
56
|
-
version: '1.
|
76
|
+
version: '1.8'
|
57
77
|
- - ">="
|
58
78
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.
|
79
|
+
version: 1.8.1
|
60
80
|
- !ruby/object:Gem::Dependency
|
61
81
|
name: rubocop-performance
|
62
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,20 +123,20 @@ dependencies:
|
|
103
123
|
requirements:
|
104
124
|
- - "~>"
|
105
125
|
- !ruby/object:Gem::Version
|
106
|
-
version: '2.
|
126
|
+
version: '2.1'
|
107
127
|
- - ">="
|
108
128
|
- !ruby/object:Gem::Version
|
109
|
-
version: 2.0
|
129
|
+
version: 2.1.0
|
110
130
|
type: :development
|
111
131
|
prerelease: false
|
112
132
|
version_requirements: !ruby/object:Gem::Requirement
|
113
133
|
requirements:
|
114
134
|
- - "~>"
|
115
135
|
- !ruby/object:Gem::Version
|
116
|
-
version: '2.
|
136
|
+
version: '2.1'
|
117
137
|
- - ">="
|
118
138
|
- !ruby/object:Gem::Version
|
119
|
-
version: 2.0
|
139
|
+
version: 2.1.0
|
120
140
|
description: |2
|
121
141
|
Nerd dice allows you to roll polyhedral dice and add bonuses as you would in
|
122
142
|
a tabletop roleplaying game. You can choose to roll multiple dice and keep a
|
@@ -150,7 +170,10 @@ files:
|
|
150
170
|
- certs/msducheminjr.pem
|
151
171
|
- checksum/nerd_dice-0.1.0.gem.sha256
|
152
172
|
- checksum/nerd_dice-0.1.0.gem.sha512
|
173
|
+
- checksum/nerd_dice-0.1.1.gem.sha256
|
174
|
+
- checksum/nerd_dice-0.1.1.gem.sha512
|
153
175
|
- lib/nerd_dice.rb
|
176
|
+
- lib/nerd_dice/configuration.rb
|
154
177
|
- lib/nerd_dice/version.rb
|
155
178
|
- nerd_dice.gemspec
|
156
179
|
homepage: https://github.com/statelesscode/nerd_dice
|
@@ -180,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
203
|
- !ruby/object:Gem::Version
|
181
204
|
version: '0'
|
182
205
|
requirements: []
|
183
|
-
rubygems_version: 3.
|
206
|
+
rubygems_version: 3.2.3
|
184
207
|
signing_key:
|
185
208
|
specification_version: 4
|
186
209
|
summary: A Ruby Gem for rolling polyhedral dice.
|
metadata.gz.sig
CHANGED
Binary file
|