nerd_dice 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +136 -4
- data/CONTRIBUTING.md +108 -0
- data/Gemfile.lock +1 -1
- data/README.md +27 -9
- data/SECURITY.md +21 -0
- data/lib/nerd_dice/convenience_methods.rb +4 -4
- data/lib/nerd_dice/version.rb +1 -1
- data/nerd_dice.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -2
- 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: a5edc034febc13a688b57e15a6254ee4523144a9619f95ade4af6284b59df578
|
4
|
+
data.tar.gz: c60102fe7b1cc8b4e09c290b2bdbb9c6602b8b6311fca595e930397f10db3ed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7097d5f6df166b480954546c6e8d8dd1b771bb67fe515093cb60a4d29aee4f3f6e244fa0eec3f099bbfb1bc2291fe9da91acda973080887cd94d98738d7ec240
|
7
|
+
data.tar.gz: 3fa7a50fe3b4217bf11e4335f9ecdce9118c432f3a5a542e36a2a9963ccd9defc602885478c782596fffe4c1a6e9a540dfdd9eb024ced1a839f44b2fbceaba1e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.rubocop.yml
CHANGED
@@ -12,7 +12,7 @@ require:
|
|
12
12
|
- rubocop-rspec
|
13
13
|
|
14
14
|
AllCops:
|
15
|
-
TargetRubyVersion:
|
15
|
+
TargetRubyVersion: 3.0
|
16
16
|
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
|
17
17
|
# to ignore them, so only the ones explicitly set in this file are enabled.
|
18
18
|
#DisabledByDefault: true
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,140 @@
|
|
1
1
|
# Nerd Dice Changelog
|
2
2
|
|
3
|
-
|
3
|
+
## master \(unreleased\)
|
4
|
+
### Added
|
5
|
+
### Changed
|
6
|
+
### Fixed
|
4
7
|
|
5
|
-
##
|
6
|
-
|
8
|
+
## 0.5.0 \(2023-02-23\)
|
9
|
+
### Added
|
10
|
+
* Add Ruby 3.1 and 3.2 to GitHub actions
|
11
|
+
* Add security policy to gem
|
12
|
+
* Add contributing guidelines to project
|
13
|
+
### Changed
|
14
|
+
* Remove Ruby 2.7 from GitHub actions
|
15
|
+
* Change minimum Ruby version to 3.0
|
16
|
+
* Refactor RuboCop to enable new cops by default and delete redundant config
|
17
|
+
* Update bundle for dependencies and development dependencies
|
18
|
+
### Fixed
|
19
|
+
* Remove hardcoded link from README
|
20
|
+
* Fix cognitive complexity code smell in convenience_methods
|
21
|
+
* Update expired gem signing certificate
|
7
22
|
|
8
|
-
|
23
|
+
## 0.4.1 \(2023-02-23\)
|
24
|
+
### Added
|
25
|
+
* Add Ruby 3.1 and 3.2 to GitHub actions
|
26
|
+
### Changed
|
27
|
+
* Remove Ruby 2.7 from GitHub actions
|
28
|
+
* Refactor RuboCop to enable new cops by default and delete redundant config
|
29
|
+
* Update bundle for dependencies and development dependencies
|
30
|
+
### Fixed
|
31
|
+
* Remove hardcoded link from README
|
32
|
+
* Fix cognitive complexity code smell in convenience_methods
|
33
|
+
* Update expired gem signing certificate
|
34
|
+
|
35
|
+
## 0.4.0 \(2021-10-23\)
|
36
|
+
### Added
|
37
|
+
* Add `NerdDice::ConvenienceMethods` method_missing mixin module that allows for dynamic invocation of patterns in the method name that get converted into calls to `NerdDice.roll_dice` or `NerdDice.total_dice` along with allowing the advantage/disadvantage mechanic or bonuses to be parsed from the method name. Full documentation of the module can be found in the [Convenience Methods Mixin](README.md#convenience-methods-mixin) section of the README.
|
38
|
+
* Add exensive specs to support the ConvenienceMethods module
|
39
|
+
### Changed
|
40
|
+
* Replace `Benchmark.bmbm` with `Benchmark.bm` in the nerd_dice_benchmark
|
41
|
+
* Add convenience_methods to nerd_dice_benchmark
|
42
|
+
* Extend `NerdDice::ConvenienceMethods` into top-level module as class methods
|
43
|
+
### Fixed
|
44
|
+
* Fix typos and horizontal scrolling in README
|
45
|
+
* Fix CodeClimate Code Smell on harvest_totals
|
46
|
+
|
47
|
+
## 0.3.1 \(2023-02-23\)
|
48
|
+
### Added
|
49
|
+
* Add Ruby 3.1 and 3.2 to GitHub actions
|
50
|
+
### Changed
|
51
|
+
* Remove Ruby 2.7 from GitHub actions
|
52
|
+
* Refactor RuboCop to enable new cops by default and delete redundant config
|
53
|
+
* Update bundle for dependencies and development dependencies
|
54
|
+
### Fixed
|
55
|
+
* Remove hardcoded link from README
|
56
|
+
* Update expired gem signing certificate
|
57
|
+
|
58
|
+
## 0.3.0 \(2021-09-11\)
|
59
|
+
### Added
|
60
|
+
* Add new options to `NerdDice::Configuration`
|
61
|
+
- `ability_score_number_of_sides`
|
62
|
+
- `ability_score_dice_rolled`
|
63
|
+
- `ability_score_dice_kept`
|
64
|
+
* Add `NerdDice.harvest_totals` method that takes in a collection and returns the results of calling `total` on each element
|
65
|
+
* Add `NerdDice.roll_ability_scores` convenience method that returns an array of `DiceSet` objects based on options and/or configuration
|
66
|
+
* Add `NerdDice.total_ability_scores` convenience method that returns an array of integers based on options and/or configuration
|
67
|
+
* Add `NerdDice::Die` class that represents a single die object and mixes in the `Comparable` module
|
68
|
+
* Add `NerdDice::DiceSet` class that represents a collection of `Die` objects and mixes in the `Enumerable` module
|
69
|
+
* Add `NerdDice::SetsRandomizationTechnique` mixin module and include in the `DiceSet` and `Die` classes
|
70
|
+
* Add `die_background_color` and `die_foreground_color` to `Configuration` class with defaults defined as constants
|
71
|
+
* Add `NerdDice.roll_dice` method that behaves in a similar fashion to `total_dice` but returns a `DiceSet` object instead of an `Integer` and has additional optional arguments relating to the non-numeric attributes of the dice
|
72
|
+
* Add `coveralls_reborn` to RSpec and GitHub actions
|
73
|
+
* Add build badge to README
|
74
|
+
* Add Code Climate maintainability integration and badge to README
|
75
|
+
* Add `nerd_dice_benchmark` script to bin directory
|
76
|
+
* Add GitHub Action CI build
|
77
|
+
- Run RSpec test suite, fail if specs fail, report coverage via Coveralls
|
78
|
+
- Run RuboCop and fail if violations
|
79
|
+
- Run benchmark suite and fail if outside of allowed ratios
|
80
|
+
### Changed
|
81
|
+
* Update RuboCop version and configuration
|
82
|
+
* Break up the NerdDice source code file into several smaller files that are included by the module
|
83
|
+
* Enforce that `NerdDice.configuration.ability_score_array_size` must be a positive duck-type integer
|
84
|
+
### Fixed
|
85
|
+
|
86
|
+
## 0.2.1 \(2023-02-23\)
|
87
|
+
### Added
|
88
|
+
* Add Ruby 3.1 and 3.2 to GitHub actions
|
89
|
+
### Changed
|
90
|
+
* Remove Ruby 2.7 from GitHub actions
|
91
|
+
* Refactor RuboCop to enable new cops by default and delete redundant config
|
92
|
+
* Update bundle for dependencies and development dependencies
|
93
|
+
### Fixed
|
94
|
+
* Remove hardcoded link from README
|
95
|
+
* Update expired gem signing certificate
|
96
|
+
|
97
|
+
## 0.2.0 \(2021-01-28\)
|
98
|
+
### Added
|
99
|
+
* Add ability to configure with `NerdDice.configure` block or `NerdDice.configuration`
|
100
|
+
- Configure `randomization_technique` as `:random_rand`, `:securerandom`, `:random_object`, or `randomized`
|
101
|
+
- Configure `refresh_seed_interval` to allow a periodic refresh of the seed
|
102
|
+
* Add `randomization_technique` option to `NerdDice.total_dice` method keyword arguments
|
103
|
+
* Add a lower-level `execute_die_roll` method that allows you to roll a single die with a generator specified
|
104
|
+
* Add ability to manually refresh or specify seed with `:refresh_seed!` method
|
105
|
+
### Changed
|
106
|
+
* Change `opts = {}` final argument to use keyword args `**opts` in the `NerdDice.total_dice` method. Now the method can be called as follows:
|
107
|
+
```ruby
|
108
|
+
# old
|
109
|
+
NerdDice.total_dice(20, 1, {bonus: 5})
|
110
|
+
NerdDice.total_dice(6, 3, {bonus: 1})
|
111
|
+
|
112
|
+
# new
|
113
|
+
NerdDice.total_dice(20, bonus: 5)
|
114
|
+
NerdDice.total_dice(6, 3, bonus: 1)
|
115
|
+
```
|
116
|
+
* 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`
|
117
|
+
* Added `securerandom` as an explicit dependency due to Ruby 3.x change to bundled gem
|
118
|
+
* `total_dice` no longer calls unqualified `.rand` which improves performance on all generators except for `:securerandom`
|
119
|
+
### Fixed
|
120
|
+
|
121
|
+
## 0.1.2 \(2023-02-23\)
|
122
|
+
### Added
|
123
|
+
### Changed
|
124
|
+
* Refactor RuboCop to enable new cops by default and delete redundant config
|
125
|
+
* Update bundle for dependencies and development dependencies
|
126
|
+
### Fixed
|
127
|
+
* Remove hardcoded link from README
|
128
|
+
* Update expired gem signing certificate
|
129
|
+
|
130
|
+
## 0.1.1 \(2020-12-12\)
|
131
|
+
### Added
|
132
|
+
### Changed
|
133
|
+
### Fixed
|
134
|
+
* Fix broken link to CHANGELOG in gemspec
|
135
|
+
* Fix RuboCop offenses from 0.1.0 and refactor specs
|
136
|
+
|
137
|
+
## 0.1.0 \(2020-12-07\)
|
138
|
+
|
139
|
+
### Added
|
140
|
+
* Add NerdDice.total_dice class method with the ability to roll multiple polyhedral dice and add a bonus
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Contributing to the NerdDice Project
|
2
|
+
|
3
|
+
Thank you for visiting the NerdDice repository and for taking interest in collaborating on the project. The primary goal of this project is educational: we want to teach people how to code with [Ruby](https://www.ruby-lang.org/en/). This is a published gem on [RubyGems](https://rubygems.org/gems/nerd_dice) and can be used in other projects using the instructions outlined in the [README](README.md#installation).
|
4
|
+
|
5
|
+
<a name="before-you-start"></a>
|
6
|
+
## Before you start...
|
7
|
+
Everything in this repository is intended to be made freely available via the [UNLICENSE](UNLICENSE.txt) and the [Creative Commons](https://creativecommons.org) [CC0 Public Domain Dedication](https://creativecommons.org/publicdomain/zero/1.0/). You can obviously submit feature requests and issues and participate in the discussions, but we can\'t accept anything into this repository and project unless you agree to make it available under the terms above. See the [legal](README.md#legal) section in the README for more information.
|
8
|
+
|
9
|
+
### Coding Videos
|
10
|
+
We make [coding videos](https://youtube.com/playlist?list=PL9kkbu1kLUeOnUtMpAnJOCtHdThx1Efkt) on our [YouTube channel](https://www.youtube.com/statelesscode) for the end-to-end of this project. If you collaborate on this project, you are consenting to potentially have the interaction featured in our videos. There is no guarantee or obligation to include your contribution or interaction in our videos, and we reserve the right to moderate inappropriate content at our own discretion.
|
11
|
+
|
12
|
+
## Ways to Contribute
|
13
|
+
There are numerous ways to contribute to this project, irrespective of your level of technical expertise. We\'ll flesh out the details and guidelines for each way to contribute below
|
14
|
+
|
15
|
+
- **[Feature requests](#feature-requests)**
|
16
|
+
- **[Bug reports](#bug-reports)**
|
17
|
+
- **[Code contributions](#code-contributions)**
|
18
|
+
- **[Documentation contributions](#documentation-contributions)**
|
19
|
+
- **[Art, design and creative input](#art-design-creative-input)**
|
20
|
+
|
21
|
+
<a name="feature-requests"></a>
|
22
|
+
### Feature requests
|
23
|
+
If you have an idea for a feature you would like to see in the NerdDice gem, feel free to [open an issue](https://github.com/statelesscode/nerd_dice/issues) in this GitHub repository. As an agile project, we strive to provide value. The better you can articulate your idea and the value it would bring to you as a user of the gem or including in your own project, it will help us determine whether or how to prioritize the idea.
|
24
|
+
|
25
|
+
Once an issue is submitted, we will likely need to discuss and clarify the feature request via comments to refine and clarify the intent, scope, and value of the feature. Precisely articulating your original feature request will help reduce the back-and-forth necessary to evaluate the story for implementation.
|
26
|
+
|
27
|
+
We can\'t guarantee that your feature request will be implemented or featured in a video, but truly welcome the collaboration and feedback of all who take interest.
|
28
|
+
|
29
|
+
<a name="bug-reports"></a>
|
30
|
+
### Bug reports
|
31
|
+
The distinction between a feature and a bug can sometimes be murky. While a feature generally refers to a request for new functionality, a bug is related to existing functionality that is not working as intended. In order to better evaluate the bug for a fix, it is extremely helpful to follow the following format:
|
32
|
+
#### Expected behavior
|
33
|
+
How you as a user or a technical evaluator would expect the application to behave. Expectation is obviously subjective, but defining your expectations as a user can help to expose usability problems with the application. If you discover a bug, we warmly welcome you to [open an issue](https://github.com/statelesscode/nerd_dice/issues) in this GitHub repository unless it is a [security bug](#security-bugs) that could be exploited and is not suitable for public collaboration.
|
34
|
+
|
35
|
+
**Examples:**
|
36
|
+
- When I use the `roll_` convenience method with `plus` and `minus` I expect it to error out.
|
37
|
+
- When I configure a randomization technique I expect that the configuration will persist until I change it or stop the Ruby interpreter
|
38
|
+
- When I roll a 6-sided die, I expect to get a number between 1 and 6, inclusive
|
39
|
+
|
40
|
+
#### Actual behavior
|
41
|
+
The actual behavior is what really happens when you try to use your feature in a way that defies your expectations. Using the same examples listed above, you can see how this might work.
|
42
|
+
|
43
|
+
**Examples:**
|
44
|
+
- The method doesn't error out and uses the plus but not the minus
|
45
|
+
- The configuration always reverts the randomization technique to `:secure_random`
|
46
|
+
- I sometimes get a 0 and I never get a 6
|
47
|
+
|
48
|
+
#### Steps to reproduce
|
49
|
+
In order to properly fix the bug, it needs to be reproducible. The more detailed and precise your steps to reproduce are, the more likely it will be that we come to the right solution in fixing the bug. Sometimes a bug will only manifest if an exact sequence of events takes place. The more complex an application gets, the harder it becomes to isolate and diagnose the root cause. An example of steps to reproduce the first problem can look something like this.
|
50
|
+
- Include the gem in the `Gemfile` and run `bundle install`
|
51
|
+
- Open the `Pry` console
|
52
|
+
- Execute the following commands
|
53
|
+
```ruby
|
54
|
+
o = Object.new
|
55
|
+
o.roll_2d8.harvest_totals
|
56
|
+
```
|
57
|
+
- A `NoMethodError` is raised
|
58
|
+
|
59
|
+
In this case the `NoMethodError` is caused by improper usage of the `harvest_totals` method, but providing specifics about what you are trying to do and what you expect to have happen can result in better clarity of documentation or a new feature.
|
60
|
+
|
61
|
+
<a name="security-bugs"></a>
|
62
|
+
#### Security bugs
|
63
|
+
If you discover a security vulnerability in the application that can be exploited, please follow our [security reporting process](SECURITY.md) instead of submitting a public issue.
|
64
|
+
|
65
|
+
<a name="code-contributions"></a>
|
66
|
+
### Code contributions
|
67
|
+
At Stateless Code our motto is \"Code Along\" and we mean it. If you have a feature that you want to implement yourself and contribute to the project, or you see an item in the [project backlog](https://github.com/statelesscode/nerd_dice/projects/1) that you want to try and tackle yourself, you are encouraged to do so.
|
68
|
+
#### Open an issue, if applicable
|
69
|
+
If there's a brand new feature you want to propose, or you want to work on a backlog item that is not yet converted into an issue, you can [open an issue](https://github.com/statelesscode/nerd_dice/issues) in this GitHub repository as you would in the sections above.
|
70
|
+
#### Fork the repository
|
71
|
+
To work on your changes, you will want to [fork this repository](https://github.com/statelesscode/nerd_dice/fork) into a repo on your own account so you can work and iterate on your feature.
|
72
|
+
#### Develop the feature
|
73
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
74
|
+
|
75
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
76
|
+
|
77
|
+
Once you have forked the repo, you can work to develop the contribution on your account. As you are working on your contribution you can commit as frequently as you'd like. \(We'll likely squash the commit down if and when it becomes time to merge the feature.\) In order to avoid rework, be sure to follow the [coding standards](#coding-standards) below. If the pull request is a candidate for merging, we will review the code and iterate on any feedback as needed.
|
78
|
+
<a name="coding-standards"></a>
|
79
|
+
#### Coding standards
|
80
|
+
Just like [Ruby on Rails](https://rubyonrails.org/) is able to increase programmer happiness by using convention over configuration, it\'s important to follow a consistent set of conventions throughout the code base to make it more consistent and maintainable. Some of these standards are just preferences while others \(like writing good tests\) are indispensable. If you feel strongly that one of these conventions should be modified and have good reasons to back it up, cordial conversation in an [issue](https://github.com/statelesscode/nerd_dice/issues) can be productive. I don\'t have all the answers and am constantly learning and evolving as a programmer myself. Just don\'t be a jerk about it.
|
81
|
+
##### Always cover your code with good tests!
|
82
|
+
Whenever it\'s possible and feasible, we recommend using a test-driven development approach \(red, green, refactor\) . We have a video on [Why Test Driven Development](https://youtu.be/AGXfZP-EhKo) on our [YouTube channel](https://www.youtube.com/statelesscode) if you\'d like to learn more.
|
83
|
+
- Write your failing test
|
84
|
+
- Implement your change in the application code to make the test pass
|
85
|
+
- Refactor your code
|
86
|
+
|
87
|
+
Tests should be meaningful, failing without your code and passing only with your code. And the assertions you make about your code should be meaningful. **Covering code with a test that doesn\'t make meaningful assertions is worse than not covering your code at all.**
|
88
|
+
|
89
|
+
##### Make sure the build will pass
|
90
|
+
Before your pull request can be merged, we need to make sure the GitHub Actions build will not fail. The following criteria must be met:
|
91
|
+
- `rubocop` needs to run without violations. If there is no way around a RuboCop violation, we can add disable-enable magic comments, but this should be seen as a last resort
|
92
|
+
- The test suite needs to pass. Running `rspec spec` from the root of the project will run the unit tests
|
93
|
+
- The code coverage can\'t decrease. This will cause the Coveralls check on the code to fail.
|
94
|
+
##### Avoid cognitive complexity and giant methods
|
95
|
+
One of the common mottoes in the Ruby ecosystem is Don\'t Repeat Yourself \(DRY\). You want to write small, reusable methods for your code instead of giant thousand line monstrosities with if-else ladders and nested loops with more if-else ladders. Breaking your code down into bite sized chunks makes it more maintainable and less bug prone. It also allows you to write smaller, more-targeted unit tests. \"Working, but ugly\" is a common early iteration condition of a feature, but before we merge it to the main branch, we want our end goal to be elegant, expressive, concise code.
|
96
|
+
##### Write a good commit message
|
97
|
+
When you\'re incrementally working on a story, it's fine to use the one-line `git commit -m "My commit message"` method of committing your code. When you squash it down at the end of the pull request, you want a good commit message for your contribution. There are many great resources on the internet about writing quality commit messages. [This one from cbeams](https://cbea.ms/git-commit/) is one of my favorites.
|
98
|
+
<a name="documentation-contributions"></a>
|
99
|
+
### Documentation contributions
|
100
|
+
You don\'t need to be a programmer to contribute to the project! If you have suggestions for clarity on documentation for the project \(as small as fixing a typo or as big as setting up a Wiki category\) you are welcome to contribute. If you aren\'t interested in learning about GitHub, git, or the version control process, you can still [open an issue](https://github.com/statelesscode/nerd_dice/issues) in this GitHub repository and provide your content contributions there. Of course, if you are comfortable with the pull request process from the [code contributions](#code-contributions) section, you are welcome to do so. We just don\'t want that to be a barrier to entry.
|
101
|
+
|
102
|
+
<a name="art-design-creative-input"></a>
|
103
|
+
### Art, design and creative input
|
104
|
+
If you have art, design, or other forms of creative input on the project that don\'t fit the above criteria, you can [open an issue](https://github.com/statelesscode/nerd_dice/issues) in this GitHub repository for that as well. As noted in the [Before you start...](#before-you-start) section, we can\'t accept any contributions unless you agree to match them to the repository standards of CC0 and/or the UNLICENSE.
|
105
|
+
|
106
|
+
<a name="guidelines-for-etiquette"></a>
|
107
|
+
## Guidelines for etiquette
|
108
|
+
See the [Conduct](README.md#conduct) section in the README for more information.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,9 +4,11 @@
|
|
4
4
|
# NerdDice
|
5
5
|
Nerd dice allows you to roll polyhedral dice and add bonuses as you would in a tabletop roleplaying game. You can choose to roll multiple dice and keep a specified number of dice such as rolling 4d6 and dropping the lowest for ability scores or rolling with advantage and disadvantage if those mechanics exist in your game.
|
6
6
|
|
7
|
+
<a name="videos"></a>
|
7
8
|
## Educational Videos By Stateless Code
|
8
9
|
The end-to-end process of developing this gem has been captured as [instructional videos](https://www.youtube.com/playlist?list=PL9kkbu1kLUeOnUtMpAnJOCtHdThx1Efkt). The videos are in a one-take style so that the mistakes along the way have troubleshooting and the concepts used to develop the gem are explained as they are covered.
|
9
10
|
|
11
|
+
<a name="installation"></a>
|
10
12
|
## Installation
|
11
13
|
|
12
14
|
Add this line to your application's Gemfile:
|
@@ -23,6 +25,7 @@ Or install it yourself as:
|
|
23
25
|
|
24
26
|
$ gem install nerd_dice
|
25
27
|
|
28
|
+
<a name="usage"></a>
|
26
29
|
## Usage
|
27
30
|
After the gem is installed, you can require it as you would any other gem.
|
28
31
|
|
@@ -30,9 +33,11 @@ After the gem is installed, you can require it as you would any other gem.
|
|
30
33
|
require 'nerd_dice'
|
31
34
|
```
|
32
35
|
|
36
|
+
<a name="module-methods-or-method-missing"></a>
|
33
37
|
### Module methods or a dynamic method_missing DSL
|
34
38
|
There are two main patterns for using NerdDice in your project. You can invoke the module-level methods like `NerdDice.total_dice` or you can include the `NerdDice::ConvenienceMethods` module to your class \(or IRB \). Once mixed in, you can dynamically invoke methods like `roll_d20_with_advantage` or `total_3d8_plus5`. See the [Convenience Methods Mixin](#convenience-methods-mixin) section for usage details.
|
35
39
|
|
40
|
+
<a name="configuration"></a>
|
36
41
|
### Configuration
|
37
42
|
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:
|
38
43
|
|
@@ -78,6 +83,7 @@ end
|
|
78
83
|
```
|
79
84
|
**Note:** You cannot set `ability_score_dice_kept` greater than `ability_score_dice_rolled`. If you try to set `ability_score_dice_kept` higher than `ability_score_dice_rolled`, an error will be raised. If you set `ability_score_dice_rolled` _lower_ than the existing value of `ability_score_dice_kept`, no error will be thrown, but `ability_score_dice_kept` will be _**modified**_ to match `ability_score_dice_rolled` and a warning will be printed.
|
80
85
|
|
86
|
+
<a name="bonus"></a>
|
81
87
|
### Rolling a number of dice and adding a bonus
|
82
88
|
You can use two different methods to roll dice. The `total_dice` method returns an `Integer` representing the total of the dice plus any applicable bonuses. The `total_dice` method does not support chaining additional methods like `highest`, `lowest`, `with_advantage`, `with_disadvantage`. The `roll_dice` method returns a `DiceSet` collection object, and allows for chaining the methods mentioned above and iterating over the individual `Die` objects. `NerdDice.roll_dice.total` and `NerdDice.total_dice` are roughly equivalent.
|
83
89
|
|
@@ -118,6 +124,7 @@ dice_set = NerdDice::DiceSet.new(6, 3, bonus: 2, randomization_technique: :rando
|
|
118
124
|
damage_type: 'psychic', foreground_color: '#FFF', background_color: '#0FF')
|
119
125
|
|
120
126
|
```
|
127
|
+
<a name="available-options"></a>
|
121
128
|
#### Available options for NerdDice::DiceSet objects
|
122
129
|
There are a number of options that can be provided when initializing a `NerdDice::DiceSet` object after specifying the mandatory number of sides and the optional number of dice \(default: 1\). The list below provides the options and indicates whether they are cascaded to the Die objects in the collection.
|
123
130
|
* `bonus` \(Duck-type Integer, _default: 0_\): Bonus or penalty to apply to the total after all dice are rolled. _**Not applied** to Die objects_
|
@@ -126,6 +133,7 @@ There are a number of options that can be provided when initializing a `NerdDice
|
|
126
133
|
* `foreground_color` \(String, _default: `NerdDice.configuration.die_foreground_color`_\): Intended foreground color to apply to the dice in the `DiceSet`. Should be a valid CSS color but is not validated or enforced and doesn\'t currently have any real functionality associated with it. _**Applied** to Die objects by default with ability to modify_
|
127
134
|
* `background_color` \(String, _default: `NerdDice.configuration.die_background_color`_\): Intended background color to apply to the dice in the `DiceSet`. Should be a valid CSS color but is not validated or enforced and doesn\'t currently have any real functionality associated with it. _**Applied** to Die objects by default with ability to modify_
|
128
135
|
|
136
|
+
<a name="properties-of-die-objects"></a>
|
129
137
|
#### Properties of individual Die objects
|
130
138
|
When initialized from a `DiceSet` object most of the properties of the `Die` object are inherited from the `DiceSet` object. In addition, there is an `is_included_in_total` public attribute that can be set to indicate whether the value of that particular die should be included in the total for its parent `DiceSet`. This property always starts out as true when the `Die` is initialized, but can be set to false.
|
131
139
|
|
@@ -144,6 +152,7 @@ die.value # => Integer between 1 and number_of_sides
|
|
144
152
|
# Rolls/rerolls the Die, sets value to the result of the roll, and returns the new value
|
145
153
|
die.roll # => Integer.
|
146
154
|
```
|
155
|
+
<a name="iterating"></a>
|
147
156
|
#### Iterating through dice in a DiceSet
|
148
157
|
The `DiceSet` class mixes in the `Enumerable` module and the `Die` object mixes in the `Comparable` module. This allows you to iterate over the dice in the collection. The `sort` method on the dice will return the die objects in ascending value from lowest to highest.
|
149
158
|
|
@@ -165,6 +174,7 @@ dice_set.each do |die|
|
|
165
174
|
# do other things
|
166
175
|
end
|
167
176
|
```
|
177
|
+
<a name="method-chaining"></a>
|
168
178
|
#### Methods and method chaining on the DiceSet
|
169
179
|
Since the DiceSet is an object, you can call methods that operate on the result returned and allow for things like the 5e advantage/disadvantage mechanic, the ability to re-roll all of the dice in the `DiceSet`, or to mark them all as included in the total.
|
170
180
|
|
@@ -203,7 +213,7 @@ dice_set.reroll_all!
|
|
203
213
|
# include_all_dice! method
|
204
214
|
dice_set.include_all_dice! # resets is_included_in_total to true for all Die objects
|
205
215
|
```
|
206
|
-
|
216
|
+
<a name="ability-scores"></a>
|
207
217
|
### Rolling Ability Scores
|
208
218
|
You can call `roll_ability_scores` or `total_ability_scores` to get back an array of `DiceSet` objects or `Integer` objects, respectively. The `total_ability_scores` method calls `total` on each `DiceSet` and returns those numbers with one value per ability score. The `Configuration` object defaults to 6 ability scores using a methodology of __4d6 drop the lowest__ by default.
|
209
219
|
|
@@ -244,6 +254,7 @@ NerdDice.roll_ability_scores(
|
|
244
254
|
```
|
245
255
|
**Note:** If you try to call this method with `ability_score_dice_kept` greater than `ability_score_dice_rolled` an error will be raised.
|
246
256
|
|
257
|
+
<a name="refreshing-seed"></a>
|
247
258
|
### Manually setting or refreshing the random generator seed
|
248
259
|
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.
|
249
260
|
|
@@ -261,8 +272,10 @@ NerdDice.refresh_seed!(randomization_technique: :randomized,
|
|
261
272
|
```
|
262
273
|
__NOTE:__ Ability to specify a seed is primarily provided for testing purposes. This makes all random numbers generated _transparently deterministic_ and should not be used if you want behavior approximating randomness.
|
263
274
|
|
275
|
+
<a name="utility-methods"></a>
|
264
276
|
### Utility Methods
|
265
277
|
|
278
|
+
<a name="harvest-totals"></a>
|
266
279
|
#### Harvesting Totals from DiceSets
|
267
280
|
The `harvest_totals` method take any collection of objects where each element responds to `total` and return an array of the results of the total method.
|
268
281
|
```ruby
|
@@ -281,11 +294,13 @@ totals_array = NerdDice.harvest_totals(totals_array)
|
|
281
294
|
### Convenience Methods Mixin
|
282
295
|
NerdDice provides an optional mixin `NerdDice::ConvenienceMethods` that uses Ruby\'s `method_missing` metaprogramming pattern to allow you to roll any number of dice with bonuses and/or the advantage/disadvantage mechanic by dynamically responding to methods that you type that match the `roll_` or `total_` pattern.
|
283
296
|
|
297
|
+
<a name="considerations-for-convenience-methods"></a>
|
284
298
|
#### Considerations for ConvenienceMethods
|
285
299
|
Before mixing in this method with a class, be aware of other `method_missing` gems that you are also mixing into your project and be sure to write robust tests. We have sought to use `method_missing` in a responsible manner that delegates back to the default implementation using `super` if the method does not match the `ConvenienceMethods` pattern, but there is no guarantee that other gems included in your project are doing the same. If you run into problems with the `ConvenienceMethods` module interacting with other `method_missing` gems, everything that the `ConvenienceMethods` module does can be replicated using the module\-level methods described above or by calling the convenience method on `NerdDice`.
|
286
300
|
|
287
301
|
Once a particular method has been called, it will define that method so that the next time it will invoke the method directly instead of traversing up the call stack for `method_missing`, which improves performance. The method will remain defined for the duration of the Ruby interpreter process.
|
288
302
|
|
303
|
+
<a name="magic-nerd-dice-class-methods"></a>
|
289
304
|
#### Calling ConvenienceMethods as NerdDice class methods
|
290
305
|
NerdDice extends the `ConvenienceMethods` module into the top-level module as class methods, so you can call the methods on the NerdDice module without needing to worry about the implications of extending it into your own class.
|
291
306
|
```ruby
|
@@ -294,7 +309,7 @@ require 'nerd_dice'
|
|
294
309
|
NerdDice.roll_3d6_lowest2_minus1
|
295
310
|
NerdDice.total_d20_with_advantage_p6
|
296
311
|
```
|
297
|
-
|
312
|
+
<a name="mixing-in-convenience-methods"></a>
|
298
313
|
#### Mixing in the ConvenienceMethods module
|
299
314
|
To mix the NerdDice DSL into your class, make sure the gem is required if not already and then use `include NerdDice::ConvenienceMethods` as shown below:
|
300
315
|
```ruby
|
@@ -324,7 +339,7 @@ class OtherClass
|
|
324
339
|
end
|
325
340
|
OtherClass.roll_3d6_lowest2_minus1 # returns NerdDice::DiceSet
|
326
341
|
```
|
327
|
-
|
342
|
+
<a name="convenience-methods-usage"></a>
|
328
343
|
#### ConvenienceMethods usage examples
|
329
344
|
Any invocation of `NerdDice.roll_dice` and `NerdDice.total_dice` can be duplicated using the `NerdDice::ConvenienceMethods` mixin. Here are some examples of what you can do with the return types and equivalent methods in the comments:
|
330
345
|
|
@@ -387,6 +402,7 @@ roll_d20_with_advantage # => DiceSet: NerdDice.roll_dice(20, 2).with_advantage(1
|
|
387
402
|
# equal to total_2d20_with_advantage but more natural
|
388
403
|
total_d20_with_advantage # => Integer: NerdDice.roll_dice(20, 2).with_advantage(1).total
|
389
404
|
```
|
405
|
+
<a name="convenience-methods-error-handling"></a>
|
390
406
|
#### ConvenienceMethods error handling
|
391
407
|
* If you try to call with a plus and a minus, an Exception is raised
|
392
408
|
* If you call with a bonus and a keyword argument and they don't match, an Exception is raised
|
@@ -397,17 +413,19 @@ roll_3d8_plus3 bonus: 1 # will raise NerdDice::Error with message about "Bonus i
|
|
397
413
|
roll_d20_with_advantage_lowest # will raise NameError using super method_missing
|
398
414
|
total_4d6_lowest3_highest2 # will raise NameError using super method_missing
|
399
415
|
```
|
416
|
+
<a name="code-along"></a>
|
417
|
+
## Code Along!
|
400
418
|
|
401
|
-
|
402
|
-
|
403
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
419
|
+
You can contribute to this project in a variety of ways. See the [CONTRIBUTING](CONTRIBUTING.md) page for more details. You don't need to be a programmer to contribute. We welcome [feature requests](CONTRIBUTING.md#feature-requests), [bug reports](CONTRIBUTING.md#bug-reports), [code contributions](CONTRIBUTING.md#code-contributions), and [documentation contributions](CONTRIBUTING.md#documentation-contributions) as well as [art, design and/or creative input](CONTRIBUTING.md#art-design-creative-input).
|
404
420
|
|
405
|
-
|
421
|
+
<a name="conduct"></a>
|
422
|
+
## Conduct
|
406
423
|
|
407
|
-
|
424
|
+
Just be polite and courteous in your interactions. It is possible to disagree passionately about ideas without making it personal. You can make a point without using language that leads to escalation. Nobody working on this project is perfect. In the event that something goes wrong, seek forgiveness and reconciliation with one another. **[Mercy triumphs over judgment](https://www.biblegateway.com/passage/?search=James+2&version=ESV)**.
|
408
425
|
|
409
|
-
|
426
|
+
We welcome and encourage your participation in this open-source project. We welcome those of all backgrounds and abilities, but we refuse to adopt the Contributor Covenant or any similar code of conduct for reasons outlined in [BURN_THE_CONTRIBUTOR_COVENANT_WITH_FIRE](BURN_THE_CONTRIBUTOR_COVENANT_WITH_FIRE.md). We welcome those who disagree about codes of conduct to contribute to this project, but we want to make it abundantly clear that Code of Conduct Trolls have no power here.
|
410
427
|
|
428
|
+
<a name="legal"></a>
|
411
429
|
## Unlicense, License, and Copyright
|
412
430
|
|
413
431
|
The project 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 additional modification in your own project\.
|
data/SECURITY.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Security Policy
|
2
|
+
|
3
|
+
## Supported Versions
|
4
|
+
|
5
|
+
As-of right now, the latest patch version of each minor version is supported, but versions earlier than `0.5.x` are deprecated and will not receive additional updates after their certificate expires on February 23, 2024.
|
6
|
+
|
7
|
+
| Version | Supported | End of Life |
|
8
|
+
| ------- | -------------------------- | ----------- |
|
9
|
+
| 0.5.x | :white_check_mark: Current | |
|
10
|
+
| 0.4.x | :warning: Deprecated | 2024-02-23 |
|
11
|
+
| 0.3.x | :warning: Deprecated | 2024-02-23 |
|
12
|
+
| 0.2.x | :warning: Deprecated | 2024-02-23 |
|
13
|
+
| 0.1.x | :warning: Deprecated | 2024-02-23 |
|
14
|
+
|
15
|
+
## Certificate Signing and Checksums
|
16
|
+
|
17
|
+
The gem is currently released with a certificate so it can be installed with the `HighSecurity` policy. The SHA-256 and SHA-512 of each released version of the gem is kept in the `checksum` directory of the GitHub repository.
|
18
|
+
|
19
|
+
## Reporting a Vulnerability
|
20
|
+
|
21
|
+
Please report (suspected) security vulnerabilities to security@statelesscode.com. We make no guarantees related to turnaround time. If the issue is confirmed, we will release a patch as soon as possible depending on complexity and severity.
|
@@ -78,10 +78,10 @@ module NerdDice
|
|
78
78
|
# roll_d20_with_advantage_lowest # will raise NameError using super method_missing
|
79
79
|
# total_4d6_lowest3_highest2 # will raise NameError using super method_missing
|
80
80
|
module ConvenienceMethods
|
81
|
-
DIS = /_(with_disadvantage|lowest)
|
82
|
-
ADV = /_(with_advantage|highest)
|
83
|
-
MOD = /(_p(lus)?\d+|_m(inus)?\d+)
|
84
|
-
OVERALL_REGEXP = /\A(roll|total)_\d*d\d+((#{ADV}|#{DIS})\d*)?#{MOD}?\z
|
81
|
+
DIS = /_(with_disadvantage|lowest)/
|
82
|
+
ADV = /_(with_advantage|highest)/
|
83
|
+
MOD = /(_p(lus)?\d+|_m(inus)?\d+)/
|
84
|
+
OVERALL_REGEXP = /\A(roll|total)_\d*d\d+((#{ADV}|#{DIS})\d*)?#{MOD}?\z/
|
85
85
|
|
86
86
|
# Override of method_missing
|
87
87
|
# * Attempts to match pattern to the regular expression matching the methods
|
data/lib/nerd_dice/version.rb
CHANGED
data/nerd_dice.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
GEM_DESCRIPTION
|
19
19
|
spec.homepage = "https://github.com/statelesscode/nerd_dice"
|
20
20
|
spec.licenses = %w[Unlicense MIT]
|
21
|
-
spec.required_ruby_version = Gem::Requirement.new(">=
|
21
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
22
22
|
|
23
23
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
24
24
|
|
data.tar.gz.sig
CHANGED
Binary file
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Duchemin
|
@@ -188,11 +188,13 @@ files:
|
|
188
188
|
- ".rubocop.yml"
|
189
189
|
- BURN_THE_CONTRIBUTOR_COVENANT_WITH_FIRE.md
|
190
190
|
- CHANGELOG.md
|
191
|
+
- CONTRIBUTING.md
|
191
192
|
- Gemfile
|
192
193
|
- Gemfile.lock
|
193
194
|
- LICENSE.txt
|
194
195
|
- README.md
|
195
196
|
- Rakefile
|
197
|
+
- SECURITY.md
|
196
198
|
- UNLICENSE.txt
|
197
199
|
- bin/console
|
198
200
|
- bin/generate_checksums
|
@@ -247,7 +249,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
247
249
|
requirements:
|
248
250
|
- - ">="
|
249
251
|
- !ruby/object:Gem::Version
|
250
|
-
version:
|
252
|
+
version: 3.0.0
|
251
253
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
252
254
|
requirements:
|
253
255
|
- - ">="
|
metadata.gz.sig
CHANGED
Binary file
|