cards_lib 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cards_lib/card.rb +5 -0
- data/lib/cards_lib/deck.rb +33 -3
- 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: c8531f89730c739c3ef6ee9578536043868ebcdb
|
4
|
+
data.tar.gz: 77f2023c5e6b4112d3c318d4ef7fb89e224dc069
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb0b0e5d91f1e221ab23def045930e38d19411364687c13884cf7f576055b8697b1e27ad6f62a622b3d869591f35f8ce334fdf953bca90de8216431bc51c4746
|
7
|
+
data.tar.gz: 6b4392f8e32b12ffe23813771bef8e962754631884dd8f89615100f412dd49b8a3108c2d01e2a83d70be91911a34e37f5d743b2bef761f277b2186f59dcbdb76
|
data/lib/cards_lib/card.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module CardsLib
|
2
2
|
class Card
|
3
3
|
def initialize(face)
|
4
|
+
raise InvalidCardFace, "face cannot be blank" if face.to_s.empty?
|
4
5
|
@face = face
|
5
6
|
end
|
6
7
|
|
@@ -8,4 +9,8 @@ module CardsLib
|
|
8
9
|
@face
|
9
10
|
end
|
10
11
|
end
|
12
|
+
|
13
|
+
class InvalidCardFace < Exception
|
14
|
+
|
15
|
+
end
|
11
16
|
end
|
data/lib/cards_lib/deck.rb
CHANGED
@@ -12,17 +12,47 @@ module CardsLib
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def peak
|
15
|
-
Array(
|
15
|
+
Array(_cards[@top..@top]).first
|
16
16
|
end
|
17
17
|
|
18
18
|
def pluck
|
19
|
-
card =
|
20
|
-
@top += 1 unless @top ==
|
19
|
+
card = peak
|
20
|
+
@top += 1 unless @top == _cards.size
|
21
21
|
card || card.tap {|i| i.define_singleton_method(:face) { nil } }
|
22
22
|
end
|
23
23
|
|
24
24
|
def return_card
|
25
25
|
@top -= 1 unless @top == 0
|
26
26
|
end
|
27
|
+
|
28
|
+
def empty?
|
29
|
+
!peak
|
30
|
+
end
|
31
|
+
|
32
|
+
def present?
|
33
|
+
!empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
def size
|
37
|
+
if @top <= _cards.size
|
38
|
+
_cards[@top..-1].size
|
39
|
+
else
|
40
|
+
0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def count
|
45
|
+
size
|
46
|
+
end
|
47
|
+
|
48
|
+
def face_up
|
49
|
+
@cards.map(&:face)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def _cards
|
55
|
+
@cards.to_a
|
56
|
+
end
|
27
57
|
end
|
28
58
|
end
|
data/lib/cards_lib/version.rb
CHANGED