rubylove-playing_cards 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a82500fd994d55cde98d6954f826aea812dd719
4
+ data.tar.gz: 7731026d15344e0dd884c1b04936722074513f97
5
+ SHA512:
6
+ metadata.gz: 1403f747dd05a01b21c1a57a38f9f9f4f7e57ddf578f71cde766656486b1ca3875f295aa17d8cf35940e405c948973c23d389cc9af11ec62c77d85327c98b745
7
+ data.tar.gz: ff2c95810537f3c008acb00444f0ed7573d96d25f857704548070b26724d1a0fd59a3311ce9e743c86eecc188e1bcc3e8a71bbe9c73b300ed631d62767a5ff24
@@ -0,0 +1,3 @@
1
+ coverage
2
+ .coveralls.yml
3
+ pkg
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ notifications:
6
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubylove-playing_cards.gemspec
4
+ gemspec
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubylove-playing_cards (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ celluloid (0.15.2)
10
+ timers (~> 1.1.0)
11
+ coderay (1.1.0)
12
+ coveralls (0.7.0)
13
+ multi_json (~> 1.3)
14
+ rest-client
15
+ simplecov (>= 0.7)
16
+ term-ansicolor
17
+ thor
18
+ docile (1.1.1)
19
+ ffi (1.9.3)
20
+ formatador (0.2.4)
21
+ guard (2.2.5)
22
+ formatador (>= 0.2.4)
23
+ listen (~> 2.1)
24
+ lumberjack (~> 1.0)
25
+ pry (>= 0.9.12)
26
+ thor (>= 0.18.1)
27
+ guard-minitest (2.1.3)
28
+ guard (~> 2.0)
29
+ minitest (>= 3.0)
30
+ listen (2.4.0)
31
+ celluloid (>= 0.15.2)
32
+ rb-fsevent (>= 0.9.3)
33
+ rb-inotify (>= 0.9)
34
+ lumberjack (1.0.4)
35
+ method_source (0.8.2)
36
+ mime-types (2.0)
37
+ minitest (5.2.1)
38
+ multi_json (1.8.2)
39
+ pry (0.9.12.4)
40
+ coderay (~> 1.0)
41
+ method_source (~> 0.8)
42
+ slop (~> 3.4)
43
+ rake (10.1.1)
44
+ rb-fsevent (0.9.4)
45
+ rb-inotify (0.9.3)
46
+ ffi (>= 0.5.0)
47
+ rest-client (1.6.7)
48
+ mime-types (>= 1.16)
49
+ simplecov (0.8.2)
50
+ docile (~> 1.1.0)
51
+ multi_json
52
+ simplecov-html (~> 0.8.0)
53
+ simplecov-html (0.8.0)
54
+ slop (3.4.7)
55
+ term-ansicolor (1.2.2)
56
+ tins (~> 0.8)
57
+ thor (0.18.1)
58
+ timers (1.1.0)
59
+ tins (0.13.1)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ bundler (~> 1.3)
66
+ coveralls
67
+ guard-minitest
68
+ rake
69
+ rubylove-playing_cards!
70
+ simplecov
@@ -0,0 +1,6 @@
1
+ guard :minitest do
2
+ # with Minitest::Spec
3
+ watch(%r{^spec/(.*)_spec\.rb})
4
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
5
+ watch(%r{^spec/spec_helper\.rb}) { 'spec' }
6
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 thatrubylove
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ # Usage
2
+
3
+ ```ruby
4
+ require 'playing_cards'
5
+
6
+ cards = Deck.build # defaults to a shoe_size of 1
7
+ cards = Deck.shuffle(cards) # shuffle!
8
+ cards = Deck.cut(cards) # cut the cards!
9
+ dealt, cards = Deck.deal(cards) # => [top_card, rest_of_the_cards]
10
+
11
+ ```
12
+
13
+ ## Health
14
+
15
+ [![Build
16
+ Status](https://travis-ci.org/thatrubylove/functional_playing_cards.png)](https://travis-ci.org/thatrubylove/functional_playing_cards)
17
+ [![Coverage
18
+ Status](https://coveralls.io/repos/thatrubylove/functional_playing_cards/badge.png?branch=master)](https://coveralls.io/r/thatrubylove/functional_playing_cards?branch=master)
19
+ [![CodeClimate
20
+ Grade](https://codeclimate.com/repos/52ce0d1de30ba02b1a000f26/badges/c216141a5d36245d2f4e/gpa.png)](https://codeclimate.com/repos/52ce0d1de30ba02b1a000f26/code)
@@ -0,0 +1,11 @@
1
+ require 'rake/testtask'
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ t.libs = ["lib", "spec"]
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,5 @@
1
+ require "playing_cards/version"
2
+ require "playing_cards/deck"
3
+
4
+ module PlayingCards
5
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: UTF-8
2
+
3
+
4
+ module PlayingCards
5
+
6
+ class Card < Struct.new(:rank, :suit)
7
+
8
+ SUITS = %w(hearts clubs spades diamonds).map(&:to_sym)
9
+ RANKS = %w(ace two three four five six seven eight nine ten jack queen king).map(&:to_sym)
10
+ VALUES = %w(11 2 3 4 5 6 7 8 9 10 10 10 10)
11
+ SBITS = %w(B D A C)
12
+ RBITS = %w(1 2 3 4 5 6 7 8 9 A B D E)
13
+
14
+ def to_s
15
+ "#{rank.to_s} of #{suit.to_sym}"
16
+ end
17
+
18
+ def to_unicode
19
+ ["1F0#{suit_bit}#{rank_bit}".hex].pack("U")
20
+ end
21
+ alias_method :inspect, :to_unicode
22
+
23
+ def backside_to_unicode
24
+ "\u{1F0A0}"
25
+ end
26
+
27
+ def value
28
+ VALUES[RANKS.index(rank)].to_i
29
+ end
30
+
31
+ private
32
+
33
+ def suit_bit
34
+ SBITS[SUITS.index(suit)]
35
+ end
36
+
37
+ def rank_bit
38
+ RBITS[RANKS.index(rank)]
39
+ end
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,41 @@
1
+ # encoding: UTF-8
2
+ require_relative 'card'
3
+
4
+ module PlayingCards
5
+
6
+ # functional representation of a deck of cards
7
+ module Deck
8
+ extend self
9
+
10
+ def build(shoe_size=1)
11
+ build_deck*shoe_size
12
+ end
13
+
14
+ def shuffle(cards)
15
+ copy = cards.dup
16
+ copy.sort_by { rand }
17
+ end
18
+
19
+ def cut(cards)
20
+ top, bottom = cut_into_2_piles(cards)
21
+ bottom + top # flop that shit
22
+ end
23
+
24
+ def deal(cards)
25
+ dealt = cards.first
26
+ [dealt, cards - [dealt]]
27
+ end
28
+
29
+ private
30
+
31
+ def cut_into_2_piles(cards)
32
+ cut_at = rand(4..cards.length-4) # never cut closer than 4 form the top or bottom
33
+ [cards[0..cut_at-1], cards[cut_at, cards.length-cut_at]]
34
+ end
35
+
36
+ def build_deck
37
+ Card::RANKS.flat_map {|rank| Card::SUITS.flat_map {|suit| Card.new(rank, suit) } }
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module PlayingCards
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'playing_cards/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubylove-playing_cards"
8
+ spec.version = PlayingCards::VERSION
9
+ spec.authors = ["thatrubylove"]
10
+ spec.email = ["thatrubylove@gmail.com"]
11
+ spec.description = %q{A playing card library in functiona ruby}
12
+ spec.summary = %q{Functional Ruby Playing Cards}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "guard-minitest"
24
+ spec.add_development_dependency "simplecov"
25
+ spec.add_development_dependency "coveralls"
26
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ module PlayingCards
4
+
5
+ describe Card do
6
+ describe "#to_s" do
7
+ it "must describe the card" do
8
+ Card.new(:ace, :hearts).to_s.must_equal "ace of hearts"
9
+ end
10
+ end
11
+
12
+ describe "#to_unicode" do
13
+ it "must show the card in unicode" do
14
+ Card.new(:ace, :hearts).to_unicode.must_equal "\u{1F0B1}"
15
+ end
16
+ end
17
+
18
+ describe "#backside_to_unicode" do
19
+ it "must show the card backside in unicode" do
20
+ Card.new(:ace, :hearts).backside_to_unicode.must_equal "\u{1F0A0}"
21
+ end
22
+ end
23
+
24
+ describe "#value" do
25
+ it "must be 11 when ace" do
26
+ Card.new(:ace, :spades).value.must_equal 11
27
+ end
28
+ it "must be 2 when two" do
29
+ Card.new(:two, :spades).value.must_equal 2
30
+ end
31
+ it "must be 3 when three" do
32
+ Card.new(:three, :spades).value.must_equal 3
33
+ end
34
+ it "must be 4 when four" do
35
+ Card.new(:four, :spades).value.must_equal 4
36
+ end
37
+ it "must be 5 when five" do
38
+ Card.new(:five, :spades).value.must_equal 5
39
+ end
40
+ it "must be 6 when six" do
41
+ Card.new(:six, :spades).value.must_equal 6
42
+ end
43
+ it "must be 7 when seven" do
44
+ Card.new(:seven, :spades).value.must_equal 7
45
+ end
46
+ it "must be 8 when eight" do
47
+ Card.new(:eight, :spades).value.must_equal 8
48
+ end
49
+ it "must be 9 when nine" do
50
+ Card.new(:nine, :spades).value.must_equal 9
51
+ end
52
+ it "must be 10 when jack" do
53
+ Card.new(:jack, :spades).value.must_equal 10
54
+ end
55
+ it "must be 10 when queen" do
56
+ Card.new(:queen, :spades).value.must_equal 10
57
+ end
58
+ it "must be 10 when king" do
59
+ Card.new(:king, :spades).value.must_equal 10
60
+ end
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ module PlayingCards
4
+ describe Deck do
5
+ describe ".build" do
6
+ describe "with a shoe size of 1" do
7
+ it "Generates a deck of 52 cards" do
8
+ deck_o_cards = Deck.build
9
+ deck_o_cards.size.must_equal 52
10
+ end
11
+ end
12
+
13
+ describe "with a shoe size of 2" do
14
+ it "Generates a deck of 104 cards" do
15
+ deck_o_cards = Deck.build(2)
16
+ deck_o_cards.size.must_equal 104
17
+ end
18
+ end
19
+ end
20
+
21
+ describe ".shuffle(cards)" do
22
+ it "will shuffle the deck" do
23
+ unshuffled = Deck.build
24
+ shuffled = Deck.shuffle(unshuffled)
25
+ shuffled.wont_equal unshuffled
26
+ end
27
+ end
28
+
29
+ describe ".cut(cards)" do
30
+ it "will cut the deck" do
31
+ cards = Deck.build
32
+ top_card = cards[0]
33
+ cards = Deck.cut(cards)
34
+ top_card.wont_equal cards[0]
35
+ end
36
+ end
37
+
38
+ describe "#deal" do
39
+ it "must pop the top card off the deck" do
40
+ cards = Deck.build
41
+ Deck.deal(cards).must_equal [cards[0], cards[1..-1]]
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,19 @@
1
+ if RUBY_ENGINE == "ruby"
2
+ begin
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ Coveralls::SimpleCov::Formatter,
7
+ SimpleCov::Formatter::HTMLFormatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter "/spec/"
11
+ end
12
+ rescue LoadError
13
+ warn "unable to load Coveralls!"
14
+ end
15
+ end
16
+ require 'minitest/autorun'
17
+
18
+
19
+ require_relative '../lib/playing_cards'
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubylove-playing_cards
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - thatrubylove
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A playing card library in functiona ruby
84
+ email:
85
+ - thatrubylove@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - Guardfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/playing_cards.rb
99
+ - lib/playing_cards/card.rb
100
+ - lib/playing_cards/deck.rb
101
+ - lib/playing_cards/version.rb
102
+ - rubylove-playing_cards.gemspec
103
+ - spec/playing_cards/card_spec.rb
104
+ - spec/playing_cards/deck_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: ''
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Functional Ruby Playing Cards
130
+ test_files:
131
+ - spec/playing_cards/card_spec.rb
132
+ - spec/playing_cards/deck_spec.rb
133
+ - spec/spec_helper.rb