card_dealer 0.1.0 → 0.3.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
- data/.rubocop.yml +12 -2
- data/CHANGELOG.md +67 -3
- data/CODE_OF_CONDUCT.md +91 -0
- data/CONTRIBUTING.md +32 -0
- data/Gemfile +8 -7
- data/Gemfile.lock +96 -57
- data/README.md +120 -11
- data/Rakefile +8 -1
- data/SECURITY.md +14 -0
- data/Steepfile +7 -0
- data/card_dealer.gemspec +44 -0
- data/lib/card_dealer/binary_deck.rb +154 -0
- data/lib/card_dealer/build_deck.rb +124 -0
- data/lib/card_dealer/card.rb +156 -19
- data/lib/card_dealer/deck.rb +94 -61
- data/lib/card_dealer/version.rb +1 -1
- data/lib/card_dealer.rb +5 -5
- data/sig/card_dealer/binary_deck.rbs +30 -0
- data/sig/card_dealer/build_deck.rbs +21 -0
- data/sig/card_dealer/card.rbs +16 -4
- data/sig/card_dealer/deck.rbs +9 -16
- data/tasks/fixtures.rake +39 -0
- metadata +21 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c3f3a33b1bc150361102599843b3cf9e7e1eb3d2b799b4116411f3445a00cf2
|
|
4
|
+
data.tar.gz: 6f32d0a5b10e0703424304aba1e8e3172a50b56066c49505c08f1752ca0c5bbe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 07f8695bf89b50776b4dbd412ed774679ae1d7cd9dccf78581148bd200b7afd30e97fdbe8eb392b640569faf3945dc738a67fd34d8501c6028216fb1d942a73f
|
|
7
|
+
data.tar.gz: b6936af01081753ab4f0e46174ddab834c2c84091923eb73794660fa2f6ea30c04c495a72121f8ffcc2ac998fb6754927b305d50bd4eabfaf3ae815d988a4c47
|
data/.rubocop.yml
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
plugins:
|
|
2
2
|
- rubocop-rake
|
|
3
3
|
- rubocop-rspec
|
|
4
4
|
|
|
5
5
|
AllCops:
|
|
6
|
-
TargetRubyVersion: 3.
|
|
6
|
+
TargetRubyVersion: 3.3
|
|
7
7
|
DisplayCopNames: true
|
|
8
8
|
DisplayStyleGuide: true
|
|
9
9
|
ExtraDetails: true
|
|
@@ -23,5 +23,15 @@ Style/Documentation:
|
|
|
23
23
|
Layout/LineLength:
|
|
24
24
|
Max: 120
|
|
25
25
|
|
|
26
|
+
Metrics/BlockLength:
|
|
27
|
+
AllowedMethods:
|
|
28
|
+
- 'namespace'
|
|
29
|
+
|
|
26
30
|
RSpec/NestedGroups:
|
|
27
31
|
Max: 4
|
|
32
|
+
|
|
33
|
+
RSpec/ExampleLength:
|
|
34
|
+
Max: 15
|
|
35
|
+
|
|
36
|
+
RSpec/MultipleMemoizedHelpers:
|
|
37
|
+
Max: 10
|
data/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,77 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/2.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
The public API covered by Semantic Versioning is the public methods of
|
|
9
|
+
`CardDealer::Card`, `CardDealer::Deck`, `CardDealer::BuildDeck`, and
|
|
10
|
+
`CardDealer::BinaryDeck`, the binary format `BinaryDeck` produces, and the
|
|
11
|
+
minimum Ruby version. Private methods and the RBS signatures under `sig/` are
|
|
12
|
+
outside it. While the version is below 1.0.0, an incompatible change bumps
|
|
13
|
+
MINOR and every other change bumps PATCH. A public item is deprecated with a
|
|
14
|
+
runtime warning naming its replacement for at least one release before it is
|
|
15
|
+
removed.
|
|
16
|
+
|
|
1
17
|
## [Unreleased]
|
|
2
18
|
|
|
19
|
+
## [0.3.0] - 2026-09-07
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- **Breaking:** Ruby 3.3 or newer is required. Ruby 3.1 and 3.2 reached end of life and are no longer tested.
|
|
24
|
+
- Development dependencies updated to their current releases (RuboCop 1.90, RSpec 3.13, Steep 2.1, rbs 4.2)
|
|
25
|
+
- CI runs on Ruby 3.3, 3.4, and 4.0
|
|
26
|
+
|
|
27
|
+
## [0.2.0] - 2023-04-01
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- `BinaryDeck` class to convert decks to binary format and back
|
|
32
|
+
(to save space when storing decks in a database, for example)
|
|
33
|
+
- `BuildDeck` class to build decks
|
|
34
|
+
- `Card` instances are now safe to use as hash keys
|
|
35
|
+
- `Card#eql?`, `Card#hash` and `Card#==` methods to compare cards and safely use them as hash keys
|
|
36
|
+
- `Card#<=>` method to make cards sortable
|
|
37
|
+
- `Deck#size` method to get the number of cards in the deck
|
|
38
|
+
- `Deck#deal` method to deal cards from the deck
|
|
39
|
+
- `Deck#to_binary_s` helper method to convert the deck to a binary string
|
|
40
|
+
- `Deck#from_binary` helper method to convert the binary string to a deck
|
|
41
|
+
- `Deck#==` method to compare decks for equality
|
|
42
|
+
- Lots of documentation
|
|
43
|
+
- [Steep](https://github.com/soutaro/steep) gem to check type correctness
|
|
44
|
+
|
|
45
|
+
### Changed
|
|
46
|
+
|
|
47
|
+
- **Breaking:** Deck building is extracted from the `Deck` class to the `BuildDeck` class.
|
|
48
|
+
`Deck#new` now takes an array of cards instead of a hash of options.
|
|
49
|
+
Call `BuildDeck.standard52`, `BuildDeck.standard36`, or `BuildDeck.custom` to build a deck.
|
|
50
|
+
- It's now possible to initialize a card with a string, e.g. `Card.new('9c')`
|
|
51
|
+
|
|
52
|
+
### Removed
|
|
53
|
+
|
|
54
|
+
- **Breaking:** `Deck#reset`. It was removed without a deprecation notice in 0.1.0,
|
|
55
|
+
so no release warned before the removal. Build a new deck with `BuildDeck` where
|
|
56
|
+
`reset` was called.
|
|
57
|
+
|
|
58
|
+
### Fixed
|
|
59
|
+
|
|
60
|
+
- All the type declarations are now correct
|
|
61
|
+
|
|
3
62
|
## [0.1.0] - 2023-03-26
|
|
4
63
|
|
|
5
64
|
Initial release!
|
|
6
65
|
|
|
7
66
|
### Added
|
|
8
67
|
|
|
9
|
-
- Card class
|
|
10
|
-
- Deck class
|
|
11
|
-
- Ability to create a decks of various
|
|
68
|
+
- `Card` class
|
|
69
|
+
- `Deck` class
|
|
70
|
+
- Ability to create a decks of various sizes, ranks, and suits
|
|
12
71
|
- Ability to shuffle a deck
|
|
13
72
|
- Ability to reset a deck
|
|
73
|
+
|
|
74
|
+
[unreleased]: https://github.com/svyatov/card_dealer/compare/v0.3.0...HEAD
|
|
75
|
+
[0.3.0]: https://github.com/svyatov/card_dealer/compare/v0.2.0...v0.3.0
|
|
76
|
+
[0.2.0]: https://github.com/svyatov/card_dealer/compare/v0.1.0...v0.2.0
|
|
77
|
+
[0.1.0]: https://github.com/svyatov/card_dealer/releases/tag/v0.1.0
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
|
|
2
|
+
# Contributor Covenant 3.0 Code of Conduct
|
|
3
|
+
|
|
4
|
+
## Our Pledge
|
|
5
|
+
|
|
6
|
+
We pledge to make our community welcoming, safe, and equitable for all.
|
|
7
|
+
|
|
8
|
+
We are committed to fostering an environment that respects and promotes the dignity, rights, and contributions of all individuals, regardless of characteristics including race, ethnicity, caste, color, age, physical characteristics, neurodiversity, disability, sex or gender, gender identity or expression, sexual orientation, language, philosophy or religion, national or social origin, socio-economic position, level of education, or other status. The same privileges of participation are extended to everyone who participates in good faith and in accordance with this Covenant.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Encouraged Behaviors
|
|
12
|
+
|
|
13
|
+
While acknowledging differences in social norms, we all strive to meet our community's expectations for positive behavior. We also understand that our words and actions may be interpreted differently than we intend based on culture, background, or native language.
|
|
14
|
+
|
|
15
|
+
With these considerations in mind, we agree to behave mindfully toward each other and act in ways that center our shared values, including:
|
|
16
|
+
|
|
17
|
+
1. Respecting the **purpose of our community**, our activities, and our ways of gathering.
|
|
18
|
+
2. Engaging **kindly and honestly** with others.
|
|
19
|
+
3. Respecting **different viewpoints** and experiences.
|
|
20
|
+
4. **Taking responsibility** for our actions and contributions.
|
|
21
|
+
5. Gracefully giving and accepting **constructive feedback**.
|
|
22
|
+
6. Committing to **repairing harm** when it occurs.
|
|
23
|
+
7. Behaving in other ways that promote and sustain the **well-being of our community**.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Restricted Behaviors
|
|
27
|
+
|
|
28
|
+
We agree to restrict the following behaviors in our community. Instances, threats, and promotion of these behaviors are violations of this Code of Conduct.
|
|
29
|
+
|
|
30
|
+
1. **Harassment.** Violating explicitly expressed boundaries or engaging in unnecessary personal attention after any clear request to stop.
|
|
31
|
+
2. **Character attacks.** Making insulting, demeaning, or pejorative comments directed at a community member or group of people.
|
|
32
|
+
3. **Stereotyping or discrimination.** Characterizing anyone’s personality or behavior on the basis of immutable identities or traits.
|
|
33
|
+
4. **Sexualization.** Behaving in a way that would generally be considered inappropriately intimate in the context or purpose of the community.
|
|
34
|
+
5. **Violating confidentiality**. Sharing or acting on someone's personal or private information without their permission.
|
|
35
|
+
6. **Endangerment.** Causing, encouraging, or threatening violence or other harm toward any person or group.
|
|
36
|
+
7. Behaving in other ways that **threaten the well-being** of our community.
|
|
37
|
+
|
|
38
|
+
### Other Restrictions
|
|
39
|
+
|
|
40
|
+
1. **Misleading identity.** Impersonating someone else for any reason, or pretending to be someone else to evade enforcement actions.
|
|
41
|
+
2. **Failing to credit sources.** Not properly crediting the sources of content you contribute.
|
|
42
|
+
3. **Promotional materials**. Sharing marketing or other commercial content in a way that is outside the norms of the community.
|
|
43
|
+
4. **Irresponsible communication.** Failing to responsibly present content which includes, links or describes any other restricted behaviors.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## Reporting an Issue
|
|
47
|
+
|
|
48
|
+
Tensions can occur between community members even when they are trying their best to collaborate. Not every conflict represents a code of conduct violation, and this Code of Conduct reinforces encouraged behaviors and norms that can help avoid conflicts and minimize harm.
|
|
49
|
+
|
|
50
|
+
When an incident does occur, it is important to report it promptly. To report a possible violation, email Leonid Svyatov at leonid@svyatov.com.
|
|
51
|
+
|
|
52
|
+
Community Moderators take reports of violations seriously and will make every effort to respond in a timely manner. They will investigate all reports of code of conduct violations, reviewing messages, logs, and recordings, or interviewing witnesses and other participants. Community Moderators will keep investigation and enforcement actions as transparent as possible while prioritizing safety and confidentiality. In order to honor these values, enforcement actions are carried out in private with the involved parties, but communicating to the whole community may be part of a mutually agreed upon resolution.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Addressing and Repairing Harm
|
|
56
|
+
|
|
57
|
+
If an investigation by the Community Moderators finds that this Code of Conduct has been violated, the following enforcement ladder may be used to determine how best to repair harm, based on the incident's impact on the individuals involved and the community as a whole. Depending on the severity of a violation, lower rungs on the ladder may be skipped.
|
|
58
|
+
|
|
59
|
+
1) Warning
|
|
60
|
+
1) Event: A violation involving a single incident or series of incidents.
|
|
61
|
+
2) Consequence: A private, written warning from the Community Moderators.
|
|
62
|
+
3) Repair: Examples of repair include a private written apology, acknowledgement of responsibility, and seeking clarification on expectations.
|
|
63
|
+
2) Temporarily Limited Activities
|
|
64
|
+
1) Event: A repeated incidence of a violation that previously resulted in a warning, or the first incidence of a more serious violation.
|
|
65
|
+
2) Consequence: A private, written warning with a time-limited cooldown period designed to underscore the seriousness of the situation and give the community members involved time to process the incident. The cooldown period may be limited to particular communication channels or interactions with particular community members.
|
|
66
|
+
3) Repair: Examples of repair may include making an apology, using the cooldown period to reflect on actions and impact, and being thoughtful about re-entering community spaces after the period is over.
|
|
67
|
+
3) Temporary Suspension
|
|
68
|
+
1) Event: A pattern of repeated violation which the Community Moderators have tried to address with warnings, or a single serious violation.
|
|
69
|
+
2) Consequence: A private written warning with conditions for return from suspension. In general, temporary suspensions give the person being suspended time to reflect upon their behavior and possible corrective actions.
|
|
70
|
+
3) Repair: Examples of repair include respecting the spirit of the suspension, meeting the specified conditions for return, and being thoughtful about how to reintegrate with the community when the suspension is lifted.
|
|
71
|
+
4) Permanent Ban
|
|
72
|
+
1) Event: A pattern of repeated code of conduct violations that other steps on the ladder have failed to resolve, or a violation so serious that the Community Moderators determine there is no way to keep the community safe with this person as a member.
|
|
73
|
+
2) Consequence: Access to all community spaces, tools, and communication channels is removed. In general, permanent bans should be rarely used, should have strong reasoning behind them, and should only be resorted to if working through other remedies has failed to change the behavior.
|
|
74
|
+
3) Repair: There is no possible repair in cases of this severity.
|
|
75
|
+
|
|
76
|
+
This enforcement ladder is intended as a guideline. It does not limit the ability of Community Managers to use their discretion and judgment, in keeping with the best interests of our community.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## Scope
|
|
80
|
+
|
|
81
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public or other spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## Attribution
|
|
85
|
+
|
|
86
|
+
This Code of Conduct is adapted from the Contributor Covenant, version 3.0, permanently available at [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/).
|
|
87
|
+
|
|
88
|
+
Contributor Covenant is stewarded by the Organization for Ethical Source and licensed under CC BY-SA 4.0. To view a copy of this license, visit [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/)
|
|
89
|
+
|
|
90
|
+
For answers to common questions about Contributor Covenant, see the FAQ at [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are provided at [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). Additional enforcement and community guideline resources can be found at [https://www.contributor-covenant.org/resources](https://www.contributor-covenant.org/resources). The enforcement ladder was inspired by the work of [Mozilla’s code of conduct team](https://github.com/mozilla/inclusion).
|
|
91
|
+
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Bug reports and pull requests are welcome at https://github.com/svyatov/card_dealer/issues.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
Install Ruby 3.3 or newer, then run:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bin/setup
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Tests and checks
|
|
14
|
+
|
|
15
|
+
`bundle exec rake` runs what CI runs: Steep, RuboCop, and RSpec. `bundle exec rake spec` runs the tests alone.
|
|
16
|
+
|
|
17
|
+
## Pull requests
|
|
18
|
+
|
|
19
|
+
1. Fork the repository and create a branch from `main`.
|
|
20
|
+
2. Make the change. A change that adds or alters behavior arrives with a test in `spec/`.
|
|
21
|
+
3. Run `bundle exec rake` and fix what it reports.
|
|
22
|
+
4. Open a pull request against `main`.
|
|
23
|
+
|
|
24
|
+
CI runs `bundle exec rake` on Ruby 3.3, 3.4, and 4.0. All three must pass before merge. Pull requests are squash merged, and their titles follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
|
|
25
|
+
|
|
26
|
+
## What an acceptable change satisfies
|
|
27
|
+
|
|
28
|
+
`bundle exec rake` passes: RuboCop with the rules in [.rubocop.yml](.rubocop.yml), Steep against the signatures in [sig/](sig/), and the suite in [spec/](spec/).
|
|
29
|
+
|
|
30
|
+
## Governance
|
|
31
|
+
|
|
32
|
+
Leonid Svyatov ([@svyatov](https://github.com/svyatov)) is the only maintainer. He reviews, merges, and releases. No succession is arranged: if he stops, the project stops unless someone forks it.
|
data/Gemfile
CHANGED
|
@@ -5,12 +5,13 @@ source "https://rubygems.org"
|
|
|
5
5
|
# Specify your gem's dependencies in card_dealer.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
-
gem "rake", "~> 13.
|
|
8
|
+
gem "rake", "~> 13.4"
|
|
9
9
|
|
|
10
|
-
gem "
|
|
11
|
-
gem "
|
|
12
|
-
gem "simplecov", require: false, group: :test
|
|
10
|
+
gem "rspec", "~> 3.13"
|
|
11
|
+
gem "simplecov", require: false
|
|
13
12
|
|
|
14
|
-
gem "rubocop", "~> 1.
|
|
15
|
-
gem "rubocop-rake", "~> 0.
|
|
16
|
-
gem "rubocop-rspec", "~>
|
|
13
|
+
gem "rubocop", "~> 1.90"
|
|
14
|
+
gem "rubocop-rake", "~> 0.7"
|
|
15
|
+
gem "rubocop-rspec", "~> 3.10"
|
|
16
|
+
|
|
17
|
+
gem "steep", require: false
|
data/Gemfile.lock
CHANGED
|
@@ -1,80 +1,119 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
card_dealer (0.
|
|
4
|
+
card_dealer (0.3.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
ast (2.4.
|
|
10
|
-
concurrent-ruby (1.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
ast (2.4.3)
|
|
10
|
+
concurrent-ruby (1.3.8)
|
|
11
|
+
csv (3.3.6)
|
|
12
|
+
diff-lcs (1.6.2)
|
|
13
|
+
ffi (1.17.4-arm64-darwin)
|
|
14
|
+
ffi (1.17.4-x86_64-linux-gnu)
|
|
15
|
+
fileutils (1.8.0)
|
|
16
|
+
json (2.21.2)
|
|
17
|
+
language_server-protocol (3.17.0.6)
|
|
18
|
+
lint_roller (1.1.0)
|
|
19
|
+
listen (3.10.0)
|
|
20
|
+
logger
|
|
21
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
22
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
|
23
|
+
logger (1.7.0)
|
|
24
|
+
parallel (2.1.0)
|
|
25
|
+
parser (3.3.12.0)
|
|
20
26
|
ast (~> 2.4.1)
|
|
27
|
+
racc
|
|
28
|
+
prism (1.9.0)
|
|
29
|
+
racc (1.8.1)
|
|
21
30
|
rainbow (3.1.1)
|
|
22
|
-
rake (13.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
rspec
|
|
31
|
+
rake (13.4.2)
|
|
32
|
+
rb-fsevent (0.11.2)
|
|
33
|
+
rb-inotify (0.11.1)
|
|
34
|
+
ffi (~> 1.0)
|
|
35
|
+
rbs (4.2.0)
|
|
36
|
+
logger
|
|
37
|
+
prism (>= 1.6.0)
|
|
38
|
+
tsort
|
|
39
|
+
regexp_parser (2.12.0)
|
|
40
|
+
rspec (3.13.2)
|
|
41
|
+
rspec-core (~> 3.13.0)
|
|
42
|
+
rspec-expectations (~> 3.13.0)
|
|
43
|
+
rspec-mocks (~> 3.13.0)
|
|
44
|
+
rspec-core (3.13.6)
|
|
45
|
+
rspec-support (~> 3.13.0)
|
|
46
|
+
rspec-expectations (3.13.5)
|
|
32
47
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
33
|
-
rspec-support (~> 3.
|
|
34
|
-
rspec-mocks (3.
|
|
48
|
+
rspec-support (~> 3.13.0)
|
|
49
|
+
rspec-mocks (3.13.8)
|
|
35
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
36
|
-
rspec-support (~> 3.
|
|
37
|
-
rspec-support (3.
|
|
38
|
-
rubocop (1.
|
|
39
|
-
json (
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
rspec-support (~> 3.13.0)
|
|
52
|
+
rspec-support (3.13.7)
|
|
53
|
+
rubocop (1.90.0)
|
|
54
|
+
json (>= 2.3)
|
|
55
|
+
language_server-protocol (~> 3.17.0.2)
|
|
56
|
+
lint_roller (~> 1.1.0)
|
|
57
|
+
parallel (>= 1.10)
|
|
58
|
+
parser (>= 3.3.0.2)
|
|
42
59
|
rainbow (>= 2.2.2, < 4.0)
|
|
43
|
-
regexp_parser (>=
|
|
44
|
-
|
|
45
|
-
rubocop-ast (>= 1.26.0, < 2.0)
|
|
60
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
61
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
46
62
|
ruby-progressbar (~> 1.7)
|
|
47
|
-
unicode-display_width (>= 2.4.0, <
|
|
48
|
-
rubocop-ast (1.
|
|
49
|
-
parser (>= 3.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
rubocop (
|
|
54
|
-
rubocop-rspec (
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
64
|
+
rubocop-ast (1.50.0)
|
|
65
|
+
parser (>= 3.3.7.2)
|
|
66
|
+
prism (~> 1.7)
|
|
67
|
+
rubocop-rake (0.7.1)
|
|
68
|
+
lint_roller (~> 1.1)
|
|
69
|
+
rubocop (>= 1.72.1)
|
|
70
|
+
rubocop-rspec (3.10.2)
|
|
71
|
+
lint_roller (~> 1.1)
|
|
72
|
+
regexp_parser (>= 2.0)
|
|
73
|
+
rubocop (~> 1.86, >= 1.86.2)
|
|
57
74
|
ruby-progressbar (1.13.0)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
securerandom (0.4.1)
|
|
76
|
+
simplecov (1.1.1)
|
|
77
|
+
steep (2.1.0)
|
|
78
|
+
concurrent-ruby (>= 1.1.10)
|
|
79
|
+
csv (>= 3.0.9)
|
|
80
|
+
fileutils (>= 1.1.0)
|
|
81
|
+
json (>= 2.1.0)
|
|
82
|
+
language_server-protocol (>= 3.17.0.4, < 4.0)
|
|
83
|
+
listen (~> 3.0)
|
|
84
|
+
logger (>= 1.3.0)
|
|
85
|
+
parser (>= 3.2)
|
|
86
|
+
prism (>= 0.25.0)
|
|
87
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
88
|
+
rbs (~> 4.2)
|
|
89
|
+
securerandom (>= 0.1)
|
|
90
|
+
strscan (>= 1.0.0)
|
|
91
|
+
terminal-table (>= 2, < 5)
|
|
92
|
+
uri (>= 0.12.0)
|
|
93
|
+
strscan (3.1.8)
|
|
94
|
+
terminal-table (4.0.0)
|
|
95
|
+
unicode-display_width (>= 1.1.1, < 4)
|
|
96
|
+
tsort (0.2.0)
|
|
97
|
+
unicode-display_width (3.2.0)
|
|
98
|
+
unicode-emoji (~> 4.1)
|
|
99
|
+
unicode-emoji (4.2.0)
|
|
100
|
+
uri (1.1.1)
|
|
65
101
|
|
|
66
102
|
PLATFORMS
|
|
67
103
|
arm64-darwin-22
|
|
104
|
+
arm64-darwin-23
|
|
105
|
+
arm64-darwin-24
|
|
106
|
+
x86_64-linux
|
|
68
107
|
|
|
69
108
|
DEPENDENCIES
|
|
70
109
|
card_dealer!
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
rubocop (~>
|
|
75
|
-
rubocop-
|
|
76
|
-
rubocop-rspec (~> 2.19)
|
|
110
|
+
rake (~> 13.4)
|
|
111
|
+
rspec (~> 3.13)
|
|
112
|
+
rubocop (~> 1.90)
|
|
113
|
+
rubocop-rake (~> 0.7)
|
|
114
|
+
rubocop-rspec (~> 3.10)
|
|
77
115
|
simplecov
|
|
116
|
+
steep
|
|
78
117
|
|
|
79
118
|
BUNDLED WITH
|
|
80
|
-
|
|
119
|
+
4.0.17
|
data/README.md
CHANGED
|
@@ -1,31 +1,140 @@
|
|
|
1
1
|
# CardDealer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
CardDealer builds, shuffles, and deals decks of playing cards for Ruby card game applications.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://rubygems.org/gems/card_dealer)
|
|
6
|
+
[](https://github.com/svyatov/card_dealer/actions/workflows/main.yml)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
- **Three deck shapes.** Builds standard 52-card and 36-card decks, and custom decks from any ranks, suits, and number of decks.
|
|
9
|
+
- **Replayable shuffles.** Shuffles with Fisher-Yates from a seed you can pass in or read back from the deck.
|
|
10
|
+
- **40 bytes for 52 cards.** Encodes a deck to a binary string for a database, a cache, or a file.
|
|
11
|
+
- **No runtime dependencies.** Requires Ruby 3.3 or newer and nothing else.
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
Add it to your Gemfile:
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
```bash
|
|
16
|
+
bundle add card_dealer
|
|
17
|
+
```
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
Then build a deck, shuffle it, and deal a hand:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
require "card_dealer"
|
|
23
|
+
|
|
24
|
+
deck = CardDealer::BuildDeck.standard52.shuffle(42)
|
|
25
|
+
deck.deal(5).map(&:to_s) # => ["8d", "4s", "Ts", "Ac", "6s"]
|
|
26
|
+
deck.size # => 47
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
A card prints as its rank (2 to 9, T, J, Q, K, A) followed by its suit (c, d, h, s).
|
|
14
30
|
|
|
15
31
|
## Usage
|
|
16
32
|
|
|
17
|
-
|
|
33
|
+
### Building a standard 52-card deck
|
|
34
|
+
|
|
35
|
+
To build a 52-card deck, call `CardDealer::BuildDeck.standard52`:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
deck = CardDealer::BuildDeck.standard52
|
|
39
|
+
deck.size # => 52
|
|
40
|
+
deck.to_a.first(3) # => ["2c", "3c", "4c"]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Building a standard 36-card deck
|
|
44
|
+
|
|
45
|
+
To build a 36-card deck, call `CardDealer::BuildDeck.standard36`:
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
deck = CardDealer::BuildDeck.standard36
|
|
49
|
+
deck.size # => 36
|
|
50
|
+
deck.to_a.first(3) # => ["6c", "7c", "8c"]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Building a custom deck
|
|
54
|
+
|
|
55
|
+
To build a custom deck, call `CardDealer::BuildDeck.custom`. `ranks` takes `:highest`, `:lowest`, or an array such as `%w[2 4 6 8 T]`. `suits` takes `:all` or an array such as `%w[d h]`:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
deck = CardDealer::BuildDeck.custom(
|
|
59
|
+
decks: 2,
|
|
60
|
+
cards_per_suit: 5,
|
|
61
|
+
ranks: :highest,
|
|
62
|
+
suits: %w[c d]
|
|
63
|
+
)
|
|
64
|
+
deck.size # => 20
|
|
65
|
+
deck.to_a.first(6) # => ["Tc", "Jc", "Qc", "Kc", "Ac", "Td"]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Shuffling and dealing cards
|
|
69
|
+
|
|
70
|
+
`CardDealer::Deck#shuffle` takes an optional seed. Without one, it generates a seed and stores it in `seed`, so you can replay the shuffle later:
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
deck = CardDealer::BuildDeck.standard52
|
|
74
|
+
deck.shuffle
|
|
75
|
+
seed = deck.seed # keep this to replay the shuffle
|
|
76
|
+
hand = deck.deal(5) # => five CardDealer::Card objects
|
|
77
|
+
deck.size # => 47
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
To burn cards before dealing, pass `burn:`:
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
deck = CardDealer::BuildDeck.standard52.shuffle(42)
|
|
84
|
+
hand = deck.deal(3, burn: 1)
|
|
85
|
+
hand.map(&:to_s) # => ["4s", "Ts", "Ac"]
|
|
86
|
+
deck.burned_cards.map(&:to_s) # => ["8d"]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
To burn cards without dealing, deal `0` cards:
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
deck = CardDealer::BuildDeck.standard52.shuffle(42)
|
|
93
|
+
deck.deal(0, burn: 10)
|
|
94
|
+
deck.burned_cards.size # => 10
|
|
95
|
+
deck.size # => 42
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Encoding a deck as a binary string
|
|
99
|
+
|
|
100
|
+
To encode a deck, call `CardDealer::BinaryDeck.encode` or `Deck#to_binary_s`. Each card takes 6 bits, after a 1, 2, or 4 byte header carrying the card count:
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
deck = CardDealer::Deck.new([CardDealer::Card.new("As"), CardDealer::Card.new("Td")])
|
|
104
|
+
encoded = CardDealer::BinaryDeck.encode(deck)
|
|
105
|
+
# - or -
|
|
106
|
+
encoded = deck.to_binary_s
|
|
107
|
+
encoded # => "\x02\xCDP"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Decoding a binary string into a deck
|
|
111
|
+
|
|
112
|
+
To decode a binary string, call `CardDealer::BinaryDeck.decode` or `Deck.from_binary`:
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
encoded = "\x02\xCDP"
|
|
116
|
+
deck = CardDealer::BinaryDeck.decode(encoded)
|
|
117
|
+
# - or -
|
|
118
|
+
deck = CardDealer::Deck.from_binary(encoded)
|
|
119
|
+
deck.to_a # => ["As", "Td"]
|
|
120
|
+
```
|
|
18
121
|
|
|
19
122
|
## Development
|
|
20
123
|
|
|
21
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
|
124
|
+
After checking out the repo, run `bin/setup` to install dependencies. Run `bundle exec rake` to run the type checker, the linter, and the tests. Run `bin/console` for an interactive prompt.
|
|
22
125
|
|
|
23
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb
|
|
126
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `lib/card_dealer/version.rb`. Add the release to `CHANGELOG.md`. Push a tag such as `v0.3.0`, which cuts the release.
|
|
24
127
|
|
|
25
128
|
## Contributing
|
|
26
129
|
|
|
27
|
-
|
|
130
|
+
Read [CONTRIBUTING.md](CONTRIBUTING.md) for setup, tests, and how to open a pull request. To report a vulnerability, follow [SECURITY.md](SECURITY.md).
|
|
131
|
+
|
|
132
|
+
## Help and status
|
|
133
|
+
|
|
134
|
+
Ask questions and report bugs in [GitHub issues](https://github.com/svyatov/card_dealer/issues).
|
|
135
|
+
|
|
136
|
+
CardDealer is actively maintained by one person. Releases happen when there is something to release.
|
|
28
137
|
|
|
29
138
|
## License
|
|
30
139
|
|
|
31
|
-
|
|
140
|
+
CardDealer is available under the [MIT License](LICENSE.txt). Releases are listed in [CHANGELOG.md](CHANGELOG.md).
|
data/Rakefile
CHANGED
|
@@ -9,4 +9,11 @@ require "rubocop/rake_task"
|
|
|
9
9
|
|
|
10
10
|
RuboCop::RakeTask.new
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
desc "Run Steep typeckecker"
|
|
13
|
+
task :steep do
|
|
14
|
+
exit(1) unless system("bundle exec steep check")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Dir["tasks/**/*.rake"].each { |t| load t }
|
|
18
|
+
|
|
19
|
+
task default: %i[steep rubocop spec]
|
data/SECURITY.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Security policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
The latest release on [rubygems.org](https://rubygems.org/gems/card_dealer) receives security fixes. Older releases do not.
|
|
6
|
+
|
|
7
|
+
## Reporting a vulnerability
|
|
8
|
+
|
|
9
|
+
Do not open a public issue for a vulnerability. Use one of these private channels:
|
|
10
|
+
|
|
11
|
+
- [GitHub private vulnerability reporting](https://github.com/svyatov/card_dealer/security/advisories/new)
|
|
12
|
+
- Email to leonid@svyatov.com
|
|
13
|
+
|
|
14
|
+
You will get a reply within 14 days. A fix ships as a new gem release, and the advisory is published after it.
|