{"id":16372512,"url":"https://github.com/mgwidmann/card_decks","last_synced_at":"2025-10-30T00:44:57.076Z","repository":{"id":20366995,"uuid":"23642295","full_name":"mgwidmann/card_decks","owner":"mgwidmann","description":null,"archived":false,"fork":false,"pushed_at":"2014-09-05T05:52:01.000Z","size":428,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-31T17:23:08.012Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mgwidmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-04T00:11:44.000Z","updated_at":"2014-09-04T23:29:52.000Z","dependencies_parsed_at":"2022-07-17T06:46:00.032Z","dependency_job_id":null,"html_url":"https://github.com/mgwidmann/card_decks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fcard_decks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fcard_decks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fcard_decks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Fcard_decks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mgwidmann","download_url":"https://codeload.github.com/mgwidmann/card_decks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239921877,"owners_count":19718842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T03:11:36.911Z","updated_at":"2025-10-30T00:44:56.991Z","avatar_url":"https://github.com/mgwidmann.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CardDecks\n\nA digital deck of cards that can be used to implement any card game desired!\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'card_decks'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install card_decks\n\n## Usage\n\n#### Example of using the deck of cards\n\n```ruby\n# Returns an already shuffled list of cards\ndeck = CardDecks::Deck.new\n\njoe   = deck.deal(5, 'Joe') # Optional second parameter\nfrank = deck.deal(5, 'Frank')\nbob   = deck.deal(5, 'Bob')\n\n# For this (simple) game, the player with the highest total card\n# value will be declared the winner\nwinner = deck.winner do |hand_one, hand_two|\n  hand_two.integer_value \u003c=\u003e hand_one.integer_value\nend\nputs \"#{winner.first.name} wins the game!\"\n```\n\n#### Configuring game rules\n\nGame rules can be configured on a per deck basis or via inheritance.\n\n##### Wild cards\n\n```ruby\ndeck = CardDecks::Deck.new\n\n# Make the Ace of Spades wild\ndeck.wild(:ace, :spades)\n# Make all Kings wild\ndeck.wild(:king)\n# Custom wild declaration -- Cards with even value are wild\ndeck.wild do |card|\n  card.integer_value % 2\nend\n# Make wild cards also make suits wild\ndeck.suits_wild!\n\nclass MyDeck \u003c CardDecks::Deck\n\n  wild :joker\n  suits_wild!\n\nend\n```\n\n##### Card Combinations\n\nCard combinations can be created to hold additional card value when they are together.\n\nFor example, matching cards with the same value could be worth more when together.\n\n```ruby\ndeck = CardDecks::Deck.new\n\n# Return the point value of the list of cards for this rule\ndeck.add_combination do |*cards|\n  # To make pairs, triples and all four matches more valuable\n  # we return an increased point value for this list of cards\n\n  # When all the cards are the same value\n  if cards.map(\u0026:integer_value).uniq!.size == 1\n    # Return the number of matches times the total value\n    cards.reduce(\u0026:+) * cards.size\n  end\n  # Returning nil simply means use the raw card value\nend\n\n# And the class version\nclass MyDeck \u003c CardDecks::Deck\n\n  [:rule_1, :rule_2, :rule_3].each {|rule| add_combination(rule) }\n\n  # Highest card is worth twice as much\n  def rule_1 *cards\n    cards.max * 2\n  end\n\n  # A wild card in your hand doubles\n  # the value of your hand\n  def rule_2 *cards\n    if cards.any?(\u0026:wild?)\n      cards.raw_integer_value * 2\n    end\n  end\n\n  # All cards are face cards adds 50 points\n  def rule_3 *cards\n    if cards.all?(\u0026:face?)\n      cards.raw_integer_value + 50\n    end\n  end\n\nend\n```\n\n\n## Contributing\n\n1. Fork it ( https://github.com/[my-github-username]/card_decks/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgwidmann%2Fcard_decks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmgwidmann%2Fcard_decks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgwidmann%2Fcard_decks/lists"}