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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d73d586f222c4bd055aa9b0ec6cb38c229b59720
4
- data.tar.gz: 6d4e6ef04c726373a4357ec23b9f09f64df24351
3
+ metadata.gz: c8531f89730c739c3ef6ee9578536043868ebcdb
4
+ data.tar.gz: 77f2023c5e6b4112d3c318d4ef7fb89e224dc069
5
5
  SHA512:
6
- metadata.gz: b8b51c87c5112c8e613133ed0f54c5a01d479b93f3e297276daed456008244828003e2ab239cc9a8eeb300801a0f06863b1f4cbe50796e949f4896d5b8d01af3
7
- data.tar.gz: 2d42c8518f4639e562985b1a2653e9f82ed01db1a4226d7d5db38e98288ab93e715e1b6ec1288057043c73581ae6c9d9cc42ee732db67ff8c51741cbef1251b9
6
+ metadata.gz: eb0b0e5d91f1e221ab23def045930e38d19411364687c13884cf7f576055b8697b1e27ad6f62a622b3d869591f35f8ce334fdf953bca90de8216431bc51c4746
7
+ data.tar.gz: 6b4392f8e32b12ffe23813771bef8e962754631884dd8f89615100f412dd49b8a3108c2d01e2a83d70be91911a34e37f5d743b2bef761f277b2186f59dcbdb76
@@ -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
@@ -12,17 +12,47 @@ module CardsLib
12
12
  end
13
13
 
14
14
  def peak
15
- Array(@cards.to_a[@top..@top]).first
15
+ Array(_cards[@top..@top]).first
16
16
  end
17
17
 
18
18
  def pluck
19
- card = Array(@cards.to_a[@top..@top]).first
20
- @top += 1 unless @top == cards.to_a.size
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
@@ -1,3 +1,3 @@
1
1
  module CardsLib
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cards_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark