cards_lib 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -3
- data/lib/cards_lib/card.rb +13 -12
- data/lib/cards_lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27b41260f30a649a682facf503c2b7affcd03ee9
|
4
|
+
data.tar.gz: 5540fb1936dc356312778adc2bd1bf6838c59e53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67d11e2507051f32b4c56faa8c692b05feb713b8779b68f82a40fb0e56f53450a3dbbc9f0579c7c46a1ce7a558854edb7a49edcf1fa4fc4907e61dea162e0408
|
7
|
+
data.tar.gz: bb7d3ee9f17ad5ab2456da4295783904f083c559a3ddacd8247b800c25404a8d069c9e7b802505a6e6f39b170a47af399fd169143667bacadc2107f3236233bb
|
data/README.md
CHANGED
@@ -2,6 +2,20 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/cards_lib.svg)](http://badge.fury.io/rb/cards_lib)[![Build Status](https://travis-ci.org/danielpclark/CardsLib.svg?branch=master)](https://travis-ci.org/danielpclark/CardsLib)[![Code Climate](https://codeclimate.com/github/danielpclark/CardsLib/badges/gpa.svg)](https://codeclimate.com/github/danielpclark/CardsLib)[![Test Coverage](https://codeclimate.com/github/danielpclark/CardsLib/badges/coverage.svg)](https://codeclimate.com/github/danielpclark/CardsLib/coverage)
|
4
4
|
|
5
|
+
I apply best practices in designing this gem and each feature has had
|
6
|
+
a LOT of thought put into it. Just look at how the Deck works. It's
|
7
|
+
designed with an immutable set of cards to draw from and to return
|
8
|
+
cards to. You can even seed it to write robust tests and get the same
|
9
|
+
results time after time. Card evaluation is written in a functional
|
10
|
+
way that allows, and is optimized for, lazy evaluation. The set
|
11
|
+
verification is as simple as handing it some cards and the names of
|
12
|
+
the rules to apply.
|
13
|
+
|
14
|
+
I'm willing to bet you that there is no other Ruby card game library
|
15
|
+
out there as easy to use, as well thought out, and as simple to
|
16
|
+
understand as mine. Come on, I dare you to use it and review it! ;-)
|
17
|
+
|
18
|
+
|
5
19
|
##Install
|
6
20
|
|
7
21
|
```
|
@@ -43,9 +57,11 @@ CardsLib::IsSet.verify(
|
|
43
57
|
|
44
58
|
##Goodies
|
45
59
|
|
46
|
-
* lib/cards_lib/is_set.rb is a golden tool in card hand verification.
|
47
|
-
|
48
|
-
* In lib/cards_lib/standard
|
60
|
+
* **lib/cards_lib/is_set.rb** is a golden tool in card hand verification.
|
61
|
+
|
62
|
+
* In **lib/cards_lib/standard.rb** there are some basic deck templates.
|
63
|
+
|
64
|
+
* In **lib/cards_lib/standard/rules/poker.rb** there are some working Poker hand verification methods.
|
49
65
|
|
50
66
|
##License
|
51
67
|
|
data/lib/cards_lib/card.rb
CHANGED
@@ -53,21 +53,22 @@ module CardsLib
|
|
53
53
|
def ordered?(other)
|
54
54
|
self.sequential?(other) ? other : nil
|
55
55
|
end
|
56
|
-
end
|
57
56
|
|
58
|
-
|
59
|
-
|
57
|
+
private
|
58
|
+
def face_from_rank_and_suit(rank, suit)
|
59
|
+
if rank && suit
|
60
|
+
[rank, ((rank.length.>(1) && suit.length.>(1)) ? " of " : ""), suit].join
|
61
|
+
else
|
62
|
+
raise InvalidRankAndSuit, "Suit and Rank provided in Hash are invalid!"
|
63
|
+
end
|
64
|
+
end
|
60
65
|
|
61
|
-
|
62
|
-
|
63
|
-
if rank && suit
|
64
|
-
[rank, ((rank.length.>(1) && suit.length.>(1)) ? " of " : ""), suit].join
|
65
|
-
else
|
66
|
-
raise InvalidRankAndSuit, "Suit and Rank provided in Hash are invalid!"
|
66
|
+
def if_hash_then_fetch(item, target)
|
67
|
+
item.is_a?(Hash) ? item.fetch(target) { nil } : nil
|
67
68
|
end
|
68
|
-
end
|
69
69
|
|
70
|
-
def if_hash_then_fetch(item, target)
|
71
|
-
item.is_a?(Hash) ? item.fetch(target) { nil } : nil
|
72
70
|
end
|
71
|
+
|
72
|
+
class InvalidCardFace < Exception; end
|
73
|
+
class InvalidRankAndSuit < Exception; end
|
73
74
|
end
|
data/lib/cards_lib/version.rb
CHANGED