deck_of_cards_handler 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 429d1307ee681bdbe06c04a5b4232a106d2ad4a0f07cbe684eaab13254e9f402
4
- data.tar.gz: 4d89bba0e091028380bb6481dacf2f48a97b3df1147a67a0f8c3bfbc67a3997b
3
+ metadata.gz: 9bb4b9ad9eeda85ab0251a2d2a0d1030ad1713956582d204726402254d1b423b
4
+ data.tar.gz: 61b9a15a482800bc77b55f3e81402314ad1668fdfb0d8d1076bec4388ab05cb6
5
5
  SHA512:
6
- metadata.gz: 971705372f4d56fc9d63d44f0d0c7b1a999209ff6f197084f8e951a58689ba45448c62ef3608eca4f97784dc9b6a4c8474aca0ce58de02e5811a3d9c654d47f4
7
- data.tar.gz: bbe3e25a0fe903c1e687455225d64aeacd033d726d910f0516a7de7b83d626aa65e9d328234f654326a86f74c90a7f479c043aabe31a696f0259eaa99c400d7f
6
+ metadata.gz: f10d2d29dabdd04098c987d992e06c303cb3a142097973aceb4f0e11cbfaf52feeea8d23418f488167fa645742accfb44ac6841efc71b84cada89b5362275865
7
+ data.tar.gz: aa06d832d4e713cade2a60cd8a06fc7d7da776e3f86b9b1ce62c6101448c91c930f4248efd7a82c84587add52de9d3d08c05205a623eca53dde2d7c5f4fcb95a
data/README.md CHANGED
@@ -1,38 +1,95 @@
1
- # DeckOfCards
1
+ # Deck of cards handler
2
2
 
3
- This is a gem that simulates the handling of a deck of cards.
4
- It provides all the moves one could do such as shuffling, cutting, dealing, culling, etc.
3
+ A ruby gem for simulating real-world deck handling: shuffle, cut, deal, cull
4
+ and more.
5
5
 
6
6
  ## Installation
7
7
 
8
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
+ Run the following terminal command:
9
9
 
10
- Install the gem and add to the application's Gemfile by executing:
11
-
12
- ```bash
13
- bundle add deck_of_card_handler
10
+ ```zsh
11
+ gem install deck_of_cards_handler
14
12
  ```
15
13
 
16
- If bundler is not being used to manage dependencies, install the gem by executing:
14
+ ## Usage examples
15
+
16
+ <details>
17
+ <summary>Create the Mnemonica stack from Stay Stack</summary>
18
+
19
+ ```ruby
20
+ require "deck_of_cards_handler"
21
+
22
+ # create a deck in stay stack order
23
+ clubs = Card.values.map { Card.new(suit: "C", value: _1) }
24
+ hearts = Card.values.map { Card.new(suit: "H", value: _1) }
25
+ diamonds = Card.values.map { Card.new(suit: "D", value: _1) }
26
+ spades = Card.values.map { Card.new(suit: "S", value: _1) }
27
+ deck = Packet.new(cards: [clubs, hearts, diamonds.reverse, spades.reverse].flatten)
28
+
29
+ # make 4 faro shuffles
30
+ 4.times do
31
+ top_half = deck.cut(number: 26)
32
+ deck.faro(other_packet: top_half)
33
+ end
34
+
35
+ # reverse the first 26 cards
36
+ top_half = deck.cut(number: 26)
37
+ top_half.reverse
38
+ deck.cards = [top_half.cards, deck.cards].flatten
39
+
40
+ # faro the 18 first cards
41
+ top_half = deck.cut(number: 18)
42
+ deck.faro(other_packet: top_half)
43
+
44
+ # cut the 9D to the bottom
45
+ deck.cut_and_complete(number: 9)
46
+ # assign a position value to the cards
47
+ deck.set_cards_positions
17
48
 
18
- ```bash
19
- gem install deck_of_card_handler
20
49
  ```
21
50
 
22
- ## Usage
51
+ </details>
52
+
53
+ <details>
54
+ <summary>Distribute 5 hands of poker</summary>
23
55
 
24
- TODO: Write usage instructions here
56
+ ```ruby
57
+ require "deck_of_cards_handler"
58
+
59
+ # create a full deck of cards
60
+ cards = []
61
+ Card.suits.each do |suit|
62
+ Card.values.each do |value|
63
+ cards << Card.new(suit:, value:)
64
+ end
65
+ end
66
+ deck = Packet.new(cards:)
67
+
68
+ deck.shuffle
69
+
70
+ hands = deck.deal_into_piles(number_of_piles: 5, number_of_cards: 5)
71
+ ```
72
+
73
+ </details>
25
74
 
26
75
  ## Development
27
76
 
28
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+ After checking out the repo, run:
29
78
 
30
- 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`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
+ ```zsh
80
+ bin/setup
81
+ ```
82
+
83
+ This installs dependencies.
31
84
 
32
- ## Contributing
85
+ Run the test suite:
33
86
 
34
- Bug reports and pull requests are welcome on GitHub at <https://github.com/simonbernard2/deck_of_cards>.
87
+ ```zsh
88
+ rake test
89
+ ```
35
90
 
36
- ## License
91
+ You can also open an interactive console for experimentation:
37
92
 
38
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
93
+ ```zsh
94
+ bin/console
95
+ ```
@@ -47,7 +47,7 @@ class Packet
47
47
  end
48
48
 
49
49
  packet = Packet.new(cards:)
50
- set_cards_positions(packet:)
50
+ packet.set_cards_positions
51
51
 
52
52
  packet
53
53
  end
@@ -71,19 +71,10 @@ class Packet
71
71
  end
72
72
 
73
73
  packet = Packet.new(cards:)
74
- set_cards_positions(packet:)
74
+ packet.set_cards_positions
75
75
 
76
76
  packet
77
77
  end
78
-
79
- private
80
-
81
- sig { params(packet: Packet).void }
82
- def set_cards_positions(packet:)
83
- packet.cards.each_with_index do |card, index|
84
- card.position = index + 1
85
- end
86
- end
87
78
  end
88
79
 
89
80
  sig { params(other_packet: Packet).void }
@@ -106,6 +97,13 @@ class Packet
106
97
  self.cards = cards.reverse
107
98
  end
108
99
 
100
+ sig { void }
101
+ def set_cards_positions
102
+ cards.each_with_index do |card, index|
103
+ card.position = index + 1
104
+ end
105
+ end
106
+
109
107
  sig { returns(T::Array[String]) }
110
108
  def to_s
111
109
  cards.map(&:to_s)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeckOfCardsHandler
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deck_of_cards_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Bernard