cards_lib 0.0.8 → 0.0.9

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: a4b204b1089602e42f73b868d994481ab50c0dfa
4
- data.tar.gz: b29e893a56c748a1143b817a63d73ce9484dd757
3
+ metadata.gz: 10716ea47a94f0d478b4503e7151f99e82f41dbb
4
+ data.tar.gz: 541e1726e3db0891a5de3c4bb581a2a097c706fe
5
5
  SHA512:
6
- metadata.gz: 1df1aa7f27a1c25cf7ccca183b1d43953535625e25a355a7637ccab41423a48b811e1134ccbf691a4cceb448fa4c7c1cda9aba34419f7ef24bca84c9d22324af
7
- data.tar.gz: 1d4691f68bfc9a6eb8956c3f53958e99a14e8011c7cbfa5fe2ce737582ab02499f2a141bfa3f7f04eb2a68bbfc35edcbfa03abd9378740f56b92502b35fe7961
6
+ metadata.gz: d32136123ac2e81a3b2a86398782ab4d0214d2fb2d953eaa779ac5af82151846a024f33bcb98921cd83b96d1852cbb6254467d4c6b5d141a901587757fbc8dd2
7
+ data.tar.gz: cac6d824f9502c16c5c82843c018396813ae5f99a2e64e44815e6bfe2550b2172834e564b6c8487b74b96b316c69e1232b66ccefd4028ff1bb8b482677dc00a6
data/.travis.yml CHANGED
@@ -1,8 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.6
4
- - 2.2.2
5
- - ruby-head
3
+ - 2.1.7
4
+ - 2.2.3
6
5
  script: bundle exec rake test
7
6
  env:
8
7
  global:
data/Gemfile CHANGED
@@ -3,3 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in CardsLib.gemspec
4
4
  gemspec
5
5
  gem "codeclimate-test-reporter", group: :test, require: nil
6
+ group :development do
7
+ gem "guard"
8
+ gem "guard-minitest"
9
+ end
data/Guardfile ADDED
@@ -0,0 +1,43 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ guard :minitest do
19
+ # with Minitest::Unit
20
+ watch(%r{^test/(.*)\/?(.*)_test\.rb$})
21
+ watch(%r{^lib/cards_lib/([^/]+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
22
+ watch(%r{^test/minitest_helper\.rb$}) { 'test' }
23
+ watch(%r{^lib/cards_lib/card.rb$}) { 'test' }
24
+
25
+ # with Minitest::Spec
26
+ # watch(%r{^spec/(.*)_spec\.rb$})
27
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
28
+ # watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
29
+
30
+ # Rails 4
31
+ # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
32
+ # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
33
+ # watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
34
+ # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
35
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
36
+ # watch(%r{^test/.+_test\.rb$})
37
+ # watch(%r{^test/test_helper\.rb$}) { 'test' }
38
+
39
+ # Rails < 4
40
+ # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
41
+ # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
42
+ # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
43
+ end
data/cards_lib.gemspec CHANGED
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.required_ruby_version = '>= 1.9.1'
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.9"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "color_pound_spec_reporter", "~> 0.0.4"
27
- spec.add_development_dependency "minitest", "~> 5.5.1"
28
- spec.add_development_dependency "minitest-reporters", "~> 1.0.0"
24
+ spec.add_development_dependency "bundler", "~> 1.10.6"
25
+ spec.add_development_dependency "rake", "~> 10.4"
26
+ spec.add_development_dependency "color_pound_spec_reporter", "~> 0.0.5"
27
+ spec.add_development_dependency "minitest", "~> 5.8.1"
28
+ spec.add_development_dependency "minitest-reporters", "~> 1.1.4"
29
29
  end
@@ -34,6 +34,14 @@ module CardsLib
34
34
  @rank || @face[0]
35
35
  end
36
36
 
37
+ def pair?(other)
38
+ self.rank == other.rank
39
+ end
40
+
41
+ def ==(other)
42
+ pair?(other) && self.suit == other.suit
43
+ end
44
+
37
45
  def <=>(other)
38
46
  @ranker.<=>(other)
39
47
  end
@@ -41,9 +49,30 @@ module CardsLib
41
49
  def sequential(other)
42
50
  @ranker.sequential(other)
43
51
  end
52
+
53
+ # return other if true
54
+ def paired?(other)
55
+ (self.rank == other.rank) ? other : NilCard.new
56
+ end
57
+
58
+ # return other if true
59
+ def suited?(other)
60
+ (self.suit == other.suit) ? other : NilCard.new
61
+ end
62
+
63
+ # returns other if true
64
+ def ordered?(other)
65
+ self.sequential(other) ? other : NilCard.new
66
+ end
44
67
  end
45
68
 
46
69
  class InvalidCardFace < Exception
47
70
 
48
71
  end
72
+
73
+ class NilCard
74
+ def method_missing(m,*a,&b)
75
+ self
76
+ end
77
+ end
49
78
  end
@@ -0,0 +1,28 @@
1
+ module CardsLib
2
+ module IsSet
3
+ class << self
4
+ def verify(cards, rules = [:unique, :paired], specs = {})
5
+ @max = specs.fetch(:max) {Float::INFINITY}
6
+ @min = specs.fetch(:min) { 3 }
7
+ rules.all? {|r| send(r, cards) } && (@min..@max).include?(cards.count)
8
+ end
9
+
10
+ private
11
+ def unique(cards)
12
+ cards.combination(2).all? {|a,b| a != b }
13
+ end
14
+
15
+ def paired(cards)
16
+ !(cards.inject(:paired?).is_a? NilCard)
17
+ end
18
+
19
+ def suited(cards)
20
+ !(cards.inject(:suited?).is_a? NilCard)
21
+ end
22
+
23
+ def ordered(cards)
24
+ !(cards.sort.inject(:ordered?).is_a? NilCard)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module CardsLib
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/cards_lib.rb CHANGED
@@ -3,6 +3,13 @@ require "cards_lib/card"
3
3
  require "cards_lib/deck"
4
4
  require "cards_lib/standard"
5
5
  require "cards_lib/ranker"
6
+ require "cards_lib/is_set"
6
7
 
7
8
  module CardsLib
9
+
10
+ # Macro
11
+ # Cards[]
12
+ # generate Card instances from string
13
+ # representations of their faces
14
+ Cards = ->*c{ c.map {|face| Card.new(face)} }
8
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cards_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.9'
19
+ version: 1.10.6
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.9'
26
+ version: 1.10.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '10.4'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '10.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: color_pound_spec_reporter
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.4
47
+ version: 0.0.5
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.4
54
+ version: 0.0.5
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 5.5.1
61
+ version: 5.8.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 5.5.1
68
+ version: 5.8.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest-reporters
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.0.0
75
+ version: 1.1.4
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.0.0
82
+ version: 1.1.4
83
83
  description: Card Game Library. Testable and Object Oriented.
84
84
  email:
85
85
  - 6ftdan@gmail.com
@@ -91,6 +91,7 @@ files:
91
91
  - ".travis.yml"
92
92
  - CODE_OF_CONDUCT.md
93
93
  - Gemfile
94
+ - Guardfile
94
95
  - LICENSE.txt
95
96
  - README.md
96
97
  - Rakefile
@@ -100,6 +101,7 @@ files:
100
101
  - lib/cards_lib.rb
101
102
  - lib/cards_lib/card.rb
102
103
  - lib/cards_lib/deck.rb
104
+ - lib/cards_lib/is_set.rb
103
105
  - lib/cards_lib/ranker.rb
104
106
  - lib/cards_lib/standard.rb
105
107
  - lib/cards_lib/version.rb
@@ -124,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
126
  version: '0'
125
127
  requirements: []
126
128
  rubyforge_project:
127
- rubygems_version: 2.4.8
129
+ rubygems_version: 2.5.0
128
130
  signing_key:
129
131
  specification_version: 4
130
132
  summary: OO Card Game Library