alucard 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +3 -0
- data/Rakefile +8 -0
- data/alucard.gemspec +22 -0
- data/lib/alucard.rb +5 -0
- data/lib/alucard/card.rb +32 -0
- data/lib/alucard/deck.rb +18 -0
- data/lib/alucard/version.rb +3 -0
- data/spec/card_spec.rb +48 -0
- data/spec/deck_spec.rb +9 -0
- data/spec/spec_helper.rb +1 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Three If By Whiskey
|
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.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/alucard.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'alucard/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "alucard"
|
8
|
+
spec.version = Alucard::VERSION
|
9
|
+
spec.authors = ["Three If By Whiskey"]
|
10
|
+
spec.email = ["3ifbyw@gmail.com"]
|
11
|
+
spec.summary = %q{Alucard is a simple card library.}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
data/lib/alucard.rb
ADDED
data/lib/alucard/card.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Alucard
|
2
|
+
class Card
|
3
|
+
RANKS = 'A23456789TJQK'
|
4
|
+
SUITS = 'SHCD'
|
5
|
+
RANK_NAMES = %w[Ace Two Three Four Five Six Seven Eight Nine Ten Jack Queen King]
|
6
|
+
SUIT_NAMES = %w[Spades Hearts Clubs Diamonds]
|
7
|
+
|
8
|
+
attr_reader :rank, :suit
|
9
|
+
|
10
|
+
def initialize spec
|
11
|
+
case spec
|
12
|
+
when Fixnum
|
13
|
+
@rank, @suit = spec % 13, spec / 13
|
14
|
+
when /([#{RANKS}])([#{SUITS}])/
|
15
|
+
@rank, @suit = RANKS.index($1), SUITS.index($2)
|
16
|
+
when /(\w+) of (\w+)/
|
17
|
+
r, s = $1.capitalize, $2.capitalize
|
18
|
+
|
19
|
+
raise ArgumentError, "Not a rank name: '#{r}'" unless RANK_NAMES.include? r
|
20
|
+
raise ArgumentError, "Not a suit name: '#{s}'" unless SUIT_NAMES.include? s
|
21
|
+
|
22
|
+
@rank, @suit = RANK_NAMES.index(r), SUIT_NAMES.index(s)
|
23
|
+
else
|
24
|
+
raise ArgumentError, "Bad card spec: '#{spec}'"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
RANKS[@rank] + SUITS[@suit]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/alucard/deck.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Alucard
|
2
|
+
attr_reader :cards
|
3
|
+
|
4
|
+
class Deck
|
5
|
+
def initialize
|
6
|
+
@cards = 52.times.map { |i| Card.new i }
|
7
|
+
end
|
8
|
+
|
9
|
+
def shuffle
|
10
|
+
@cards.shuffle!
|
11
|
+
end
|
12
|
+
|
13
|
+
def deal n
|
14
|
+
raise "Can't deal #{n} cards!" if @cards.size < n
|
15
|
+
@cards.pop n
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/card_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Alucard
|
4
|
+
|
5
|
+
describe "Card.new with a numeric spec" do
|
6
|
+
let (:ace_of_spades) { Card.new 0 }
|
7
|
+
let (:king_of_diamonds) { Card.new 51 }
|
8
|
+
|
9
|
+
it "should have the appropriate rank" do
|
10
|
+
expect(ace_of_spades.rank).to be 0
|
11
|
+
expect(king_of_diamonds.rank).to be 12
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have the appropriate suit" do
|
15
|
+
expect(ace_of_spades.suit).to be 0
|
16
|
+
expect(king_of_diamonds.suit).to be 3
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Card.new with a rank/suit spec" do
|
21
|
+
let (:ace_of_spades) { Card.new 'AS' }
|
22
|
+
let (:king_of_diamonds) { Card.new 'KD' }
|
23
|
+
|
24
|
+
it "should have the appropriate rank" do
|
25
|
+
expect(ace_of_spades.rank).to be 0
|
26
|
+
expect(king_of_diamonds.rank).to be 12
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have the appropriate suit" do
|
30
|
+
expect(ace_of_spades.suit).to be 0
|
31
|
+
expect(king_of_diamonds.suit).to be 3
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Card.new with a name spec" do
|
36
|
+
let (:ace_of_spades) { Card.new 'Ace of Spades' }
|
37
|
+
let (:king_of_diamonds) { Card.new 'King of Diamonds' }
|
38
|
+
|
39
|
+
it "should have the appropriate rank" do
|
40
|
+
expect(ace_of_spades.rank).to be 0
|
41
|
+
expect(king_of_diamonds.rank).to be 12
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have the appropriate suit" do
|
45
|
+
expect(ace_of_spades.suit).to be 0
|
46
|
+
expect(king_of_diamonds.suit).to be 3
|
47
|
+
end
|
48
|
+
end
|
data/spec/deck_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../../lib/alucard', __FILE__)
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alucard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Three If By Whiskey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description:
|
47
|
+
email:
|
48
|
+
- 3ifbyw@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- alucard.gemspec
|
59
|
+
- lib/alucard.rb
|
60
|
+
- lib/alucard/card.rb
|
61
|
+
- lib/alucard/deck.rb
|
62
|
+
- lib/alucard/version.rb
|
63
|
+
- spec/card_spec.rb
|
64
|
+
- spec/deck_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: ''
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.23
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Alucard is a simple card library.
|
91
|
+
test_files:
|
92
|
+
- spec/card_spec.rb
|
93
|
+
- spec/deck_spec.rb
|
94
|
+
- spec/spec_helper.rb
|