para_dice 0.6.0 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e84f99eb4b926c858463cb3e1f5d38795aa83a42
4
- data.tar.gz: 397c26eec927b3da43e367c705483c986f614e46
3
+ metadata.gz: 2c52cca73b5eb7c28d3ed30e720952ac0a7f1e92
4
+ data.tar.gz: 6c35a7405db12a7eab68246f7fd253bdd05cde5b
5
5
  SHA512:
6
- metadata.gz: f442d38d1210ab0b9f87db37def9f475e620d944c5eb7bbce849487ac4e1d2468d34a097a93ee7a9f8610faaeed30eb1429a5ccda648619aabd9ff0b87d7280a
7
- data.tar.gz: 16c1d751f0ddf24bd9cedbd555fc450917ed4c5daeb7c60c33adcf14a6b74e76c16cd737b60af3dc93824f31bdaebcc9df50bab57ef34d7d708986ae8abce6c2
6
+ metadata.gz: debb2dfe10f76fca6d6c52df9572d3920983d5fda3b4a0acf985d931f54946dd11854007b014d71369d214cb7c3d4e758f9a4afb87cb363a1899d6cd89bd4717
7
+ data.tar.gz: 0b2e3a34767b2bd01dacf5bf530480210ed61859eb688824176b111759427dc58bf1bf52e76adf1d1cb5a6509d38b0f91e539e73c08e16ed8572d290d4c02292
@@ -39,7 +39,7 @@ rules:
39
39
  # - prefer_ruby_19_new_hash_syntax
40
40
  # - prefer_ruby_19_new_lambda_syntax
41
41
  # - prefer_single_quoted_strings
42
- # - reduce_number_of_params
42
+ - reduce_number_of_params
43
43
  # - refactor_complex_class
44
44
  # - refactor_complex_method
45
45
  # - remove_trailing_whitespace
@@ -0,0 +1 @@
1
+ --plugin virtus
data/Gemfile CHANGED
@@ -1,9 +1,7 @@
1
1
  source 'https://rubygems.org'
2
- group :test do
3
- gem "codeclimate-test-reporter", '~>0.4.1', require: nil
4
- gem 'pullreview-coverage', require: false
5
- end
6
2
 
7
- gem 'tty', '~>0.1.0', group: :development
8
- # Specify your gem's dependencies in para_dixe.gemspec
3
+ gem 'yard-virtus', '0.0.5', github: 'anithri/yard-virtus'
4
+
5
+ # gem 'tty', '~>0.1.0', group: :development
6
+ # Specify your gem's dependencies in para_dice.gemspec
9
7
  gemspec
data/README.md CHANGED
@@ -1,15 +1,14 @@
1
- # ParaDice
1
+ # ParaDice [![Gem Version](https://badge.fury.io/rb/para_dice.svg)](http://badge.fury.io/rb/para_dice)
2
2
 
3
3
  [![Build Status](https://travis-ci.org/anithri/para_dice.svg?branch=master)](https://travis-ci.org/anithri/para_dice)
4
- [![Code Climate](https://codeclimate.com/github/anithri/para_dice/badges/gpa.svg)](https://codeclimate.com/github/anithri/para_dice)
5
- [![Test Coverage](https://codeclimate.com/github/anithri/para_dice/badges/coverage.svg)](https://codeclimate.com/github/anithri/para_dice)
6
4
  [![Dependency Status](https://gemnasium.com/anithri/para_dice.svg)](https://gemnasium.com/anithri/para_dice)
7
5
  [![PullReview stats](https://www.pullreview.com/github/anithri/para_dice/badges/master.svg?)](https://www.pullreview.com/github/anithri/para_dice/reviews/master)
6
+ [![Inline docs](http://inch-ci.org/github/anithri/para_dice.svg?branch=master)](http://inch-ci.org/github/anithri/para_dice)
8
7
 
9
8
  An extensible dice gem.
10
9
 
11
10
  ## Introduction
12
- ParaDice is a ruby library that provides customizable dice and results of rolling one or more.
11
+ ParaDice is a ruby library that provides a customizable dice system made of 4 component. Dice, Bags, Cups, and Readers. Dice is pretty obvious. Cups are a group of dice ready to roll and read the result. Bags are a container that keep track of dice and creates cups. Finally the readers are used to take raw results and produce final results with.
13
12
 
14
13
  ## Installation
15
14
 
@@ -27,19 +26,23 @@ Or install it yourself as:
27
26
 
28
27
  $ gem install para_dice
29
28
 
30
-
31
29
  ## Usage
32
30
 
33
31
  ```ruby
34
- require para_dice
32
+ require 'para_dice'
33
+
34
+ # Create a simple die
35
+ coin = ParaDice::StringDie.new(faces: ['heads','tails'], name: 'coin')
36
+ coin.roll # => 'heads' or 'tails'
35
37
 
36
38
  # Use a set of polyhedral dice
37
- bag = ParaDice::GenerateDiceBag.poly
39
+ bag = ParaDice::PolyBag.new
38
40
  # Get a dice cup to roll 3 d6 in this case
39
41
  cup = bag.take_cup([:d6, :d6, :d6])
42
+ # use roll to roll the dice and read the results
43
+ cup.roll # 10
44
+ #use roll! to roll the dice and return raw values
40
45
  cup.roll! # [4, 2, 4]
41
- result = cup.roll # ParaDice::Results::Sum object
42
- result.raw # [4,2,
43
46
 
44
47
  ```
45
48
  ## Contributing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
@@ -12,10 +12,10 @@ module ParaDice
12
12
  attribute :name, String, default: 'Dice Bag'
13
13
  # @!attribute dice
14
14
  # @return [Hash<String,Die>] default: {}
15
- attribute :dice, Hash[String => Die], default: ->(*a) { {} }
15
+ attribute :dice, Hash[String => Die], default: {}
16
16
  # @!attribute default_readers
17
17
  # @return [Array<#resolve>] default: []
18
- attribute :default_readers, Array, default: ->(*a) { [] }
18
+ attribute :default_readers, Array, default: []
19
19
  # @!attribute rng
20
20
  # @return [Random] default: Random.new
21
21
  attribute :rng, Random, default: ->(*a) { Random.new }
@@ -1,17 +1,33 @@
1
1
  require 'para_dice/die'
2
2
  module ParaDice
3
+ # A Cup hold a selection of dice and a selection of readers. It's main purpose
4
+ # is to provide a reusable component that you can call #roll on and get a
5
+ # complex result from
3
6
  class Cup
4
7
  # Includes Virtus.model
5
8
  include Virtus.model
6
9
 
10
+ # @!attribute [rw] Dice
11
+ # @return [Array<ParaDice::Die]
7
12
  attribute :dice, Array[ParaDice::Die], default: []
8
- attribute :rng, Random, default: ->(c, a) { Random.new }
13
+
14
+ # @!attribute [rw] rng
15
+ # @return [Random]
16
+ attribute :rng, Random, default: ->(*a) { Random.new }
17
+
18
+ # @!attribute [rw] readers
19
+ # @return [Array<#resolvce>]
9
20
  attribute :readers, Array, default: []
10
21
 
22
+ # roll reach die in cup and call each reader in turn on the results, return
23
+ # the result of the last reader
24
+ # @param [Random,#rand] roll_rng default: self.rng
11
25
  def roll(roll_rng = rng)
12
26
  readers.reduce(roll!(roll_rng)) { |faces, reader| reader.resolve(faces) }
13
27
  end
14
28
 
29
+ # roll each die in cup using roll_rng and return array of raw results from
30
+ # @param [Random,#rand] roll_rng default: self.rng
15
31
  def roll!(roll_rng = rng)
16
32
  dice.map { |d| d.roll(roll_rng) }
17
33
  end
@@ -8,16 +8,17 @@ module ParaDice
8
8
  module Die
9
9
  ERROR_MSG = ': Must be implemented in your Die class or included in a faces module.'
10
10
 
11
- # @!method initialize(params = {})
12
- # @see Virtus for details
13
- # creates new Die object and populates it's attributes with values from params.
14
- # this list may not be comprehensive. Check modules you include for other
15
- # options.
16
- # @param [Hash] params
17
- # @option params [String] :name
18
- # @option params [Random] :rng
19
- # @option params [String] :description
20
-
11
+ # @!scope class
12
+ # @!method new(params = {})
13
+ # @see Virtus for details
14
+ # creates new Die object and populates it's attributes with values from params.
15
+ # this list may not be comprehensive. Check modules you include for other
16
+ # options.
17
+ # @param [Hash] params
18
+ # @option params [String] :name
19
+ # @option params [Random] :rng
20
+ # @option params [String] :description
21
+ # @return [Die]
21
22
  include Virtus.module
22
23
 
23
24
  # @!attribute [rw] name
@@ -1,11 +1,12 @@
1
1
  require 'para_dice/die'
2
2
  module ParaDice
3
+ # container module to put Face modules in
3
4
  module Faces
4
5
  # a module to be included into a ParaDice::Die or similar object.
5
- # Uses an Array object to provide faces, and provides count and
6
- # random_face methods
6
+ # Uses an Array object to provide faces, and provides count and
7
+ # random_face methods
7
8
  # @note, these are strings, but the pattern could easily be symbols, numbers,
8
- # json objects, etc. the only difference would be in how you
9
+ # json objects, etc. the only difference would be in how you
9
10
  module Arrayed
10
11
  include ParaDice::Die
11
12
 
@@ -1,9 +1,10 @@
1
1
  require 'virtus'
2
2
  module ParaDice
3
+ # container module to put Face modules in
3
4
  module Faces
4
5
  # a module to be included into a ParaDice::Die or similar object.
5
- # Uses a Range object to provide a faces, and provides special count and
6
- # random_face options
6
+ # Uses a Range object to provide a faces, and provides special count and
7
+ # random_face options
7
8
  module Ranged
8
9
  include Virtus.module
9
10
 
@@ -6,6 +6,12 @@ module ParaDice
6
6
  include Die
7
7
  include Faces::Ranged
8
8
 
9
+ # @!method initialize(params = {})
10
+ # initialize a new object, Inherited via Die from Virtus
11
+ # @params [Hash] params hash containing all data for object
12
+ # @option params params [String] :name
13
+
14
+ # given a maximum value, return a NumberedDie with max faces from 1..max
9
15
  def self.get(max)
10
16
  self.new(name: "d#{max}", range: 1..max)
11
17
  end
@@ -1,14 +1,18 @@
1
+ # part of the paradice gem
1
2
  module ParaDice
3
+ # operators that must have a #resolve method that can be passed an array
2
4
  module Results
3
5
  # Results class to implement a roll 5 and keep 3 style of play
4
6
  class AndKeep
7
+ # default sort order. passed to sort_by. defaults to a simple pass through
8
+ DEFAULT_SORT_BY = ->(obj) { obj }
9
+
5
10
  # @!attribute [rw] :default_keep
6
11
  # @return [Fixnum] the default number of dice to keep
7
12
  # @!attribute [rw] :default_low_results
8
13
  # @return [Boolean] keep dice off of the low end of the order. false by default
9
14
  # @!attribute [rw] :default_sort_by
10
15
  # @return [Proc] the sort by block defaults to passing the object through to sort
11
- DEFAULT_SORT_BY = ->(obj) { obj }
12
16
  attr_accessor :default_keep, :default_low_results, :default_sort_by
13
17
  # @param [Regex,String] default_keep
14
18
  def initialize(default_keep = nil)
@@ -1,13 +1,21 @@
1
1
  require 'facets/string/modulize'
2
- require 'hashie'
3
2
 
4
3
  module ParaDice
4
+ # provides utility methods used by other parts of ParaDice.
5
5
  module Utility
6
- class IndifferentHash < Hash
7
- include Hashie::Extensions::IndifferentAccess
8
- end
9
-
10
- # TODO ADD EXAMPLE
6
+ # Generate a Class or Module from a representation for the class.
7
+ # @example Get a module from
8
+ # ParaDice::Utility.module_from(String) # => String
9
+ # ParaDice::Utility.module_from('string') # => String
10
+ # ParaDice::Utility.module_from('String') # => String
11
+ # ParaDice::Utility.module_from('STRING') # => String
12
+ # ParaDice::Utility.module_from(:string) # => String
13
+ # ParaDice::Utility.module_from(:String) # => String
14
+ # ParaDice::Utility.module_from('paradise/utility') # => Paradise::Utility
15
+ # ParaDice::Utility.module_from('paradise__utility') # => Paradise::Utility
16
+ # ParaDice::Utility.module_from('Paradise::Utility') # => Paradise::Utility
17
+ # ParaDice::Utility.module_from('Utility', 'ParaDice') # => Paradise::Utility
18
+ # ParaDice::Utility.module_from('Utility', ParaDice) # => Paradise::Utility
11
19
  # @param [Class,Module,#to_s] name
12
20
  # @param [Class, Module, #to_s] namespace
13
21
  # @return [false] if no name is found at top level or namespace
@@ -21,6 +29,9 @@ module ParaDice
21
29
 
22
30
  # to_summary creates a hash and populates it with uniq elements of the
23
31
  # array, and the count of how many there are
32
+ # @example Make a summary from array
33
+ # arr = [2,3,1,2,3,2,3]
34
+ # ParaDice::Utility.to_summary(arr) # => { 1 => 1, 2 => 3, 3 => 3}
24
35
  # @param [Array] arr a list to summarize
25
36
  # @return [Hash]
26
37
  def self.to_summary(arr)
@@ -29,7 +40,9 @@ module ParaDice
29
40
 
30
41
  # from_summary creates an array and populates with a number of each key
31
42
  # equal to the value for that key
32
- # TODO ADD EXAMPLE
43
+ # @example Make an array from a Summary Hash
44
+ # summary = {foo: 3, bar: 1, baz: 2}
45
+ # ParaDice::Utility.from_summary(summary) # => [:foo,:foo,:foo,:bar,:baz,:baz]
33
46
  # @param [Hash<Object,Fixnum>] summary a hash to inflate a summary into an array
34
47
  # @return [Array<Object>]
35
48
  def self.from_summary(summary)
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.version = File.read('VERSION')
8
8
  spec.authors = ["Scott M Parrish"]
9
9
  spec.email = ["anithri@gmail.com"]
10
- spec.summary = %q{Game Dev Toolbox.}
10
+ spec.summary = %q{Game Board Component - Dice.}
11
11
  spec.description = %q{A Toolbox to help me build a board game.}
12
12
  spec.homepage = ""
13
13
  spec.license = "MIT"
@@ -19,16 +19,15 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_runtime_dependency 'virtus', '~> 1.0.3'
21
21
  spec.add_runtime_dependency 'facets', '~> 2.9.3'
22
- spec.add_runtime_dependency 'hashie', '~> 3.3.1'
23
22
 
24
23
  spec.add_development_dependency 'bundler', '~> 1.7.6'
25
24
  spec.add_development_dependency 'yard', '~> 0.8.7.6'
26
25
  spec.add_development_dependency 'rake', '~> 10.3.2'
27
26
  spec.add_development_dependency 'rspec', '~> 3.1.0'
28
- spec.add_development_dependency 'guard-rspec', '~> 4.3.1'
29
- spec.add_development_dependency 'guard-bundler', '~> 2.0.0'
30
27
  spec.add_development_dependency 'version', '~> 1.0.0'
31
28
  spec.add_development_dependency 'fuubar', '~> 2.0.0'
32
-
29
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.1'
30
+ spec.add_development_dependency 'pullreview-coverage'
31
+
33
32
  end
34
33
 
@@ -56,8 +56,8 @@ describe ParaDice::Cup do
56
56
  context 'with a hash_reader' do
57
57
  subject { cup.roll(rng) }
58
58
  let(:readers) { [ParaDice::Results::Hash] }
59
- let(:cup) { described_class.new(dice: dice_list, readers: readers)
60
- it { is_expected.to eq('baz' => 3, 'foo' => 1, 'bar' => 1) } }
59
+ let(:cup) { described_class.new(dice: dice_list, readers: readers) }
60
+ it { is_expected.to eq('baz' => 3, 'foo' => 1, 'bar' => 1) }
61
61
  end
62
62
  context 'with a cancel_opposing reader' do
63
63
  subject { cup.roll(rng) }
@@ -1,19 +1,11 @@
1
1
  require 'rspec'
2
2
  require 'para_dice/numbered_die'
3
3
  describe ParaDice::NumberedDie do
4
-
5
4
  describe '#get(max, offset = 0)' do
5
+ let(:arg) { 6 }
6
+ let(:faces) { [1, 2, 3, 4, 5, 6] }
6
7
  subject { described_class.get(arg) }
7
-
8
- context 'only max' do
9
- let(:arg) { 6 }
10
-
11
- it { expect(subject.name).to eq 'd6' }
12
- it do
13
- is_expected.to have_attributes(name: 'd6',
14
- description: '',
15
- faces: [1, 2, 3, 4, 5, 6])
16
- end
17
- end
8
+ it { is_expected.to be_a described_class }
9
+ it { is_expected.to have_attributes(name: 'd6', face_count: 6, faces: faces) }
18
10
  end
19
11
  end
@@ -4,5 +4,6 @@ require 'para_dice/results/array'
4
4
 
5
5
  describe ParaDice::Results::Array do
6
6
  let(:faces) { [:foo, :bar, :baz] }
7
- subject { described_class.resolve(faces).should be faces }
7
+ subject { described_class.resolve(faces) }
8
+ it { is_expected.to eq(faces) }
8
9
  end
@@ -3,8 +3,7 @@ require 'rspec'
3
3
  require 'para_dice'
4
4
 
5
5
  describe ParaDice do
6
- it 'let me have a 6 sided die', rewrite: true do
7
- die = ParaDice.numbered_die(6)
8
- expect(die).to be_a_kind_of ParaDice::Die
9
- end
6
+ subject { ParaDice.numbered_die(6) }
7
+ it { is_expected.to be_a ParaDice::Die }
8
+ it { is_expected.to have_attributes name: 'd6' }
10
9
  end
@@ -1,6 +1,6 @@
1
1
  require 'codeclimate-test-reporter'
2
2
  require 'pullreview/coverage_reporter'
3
- #CodeClimate::TestReporter.start
3
+ # CodeClimate::TestReporter.start
4
4
  PullReview::CoverageReporter.start
5
5
 
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para_dice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott M Parrish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2014-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.9.3
41
- - !ruby/object:Gem::Dependency
42
- name: hashie
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 3.3.1
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 3.3.1
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -109,21 +95,21 @@ dependencies:
109
95
  - !ruby/object:Gem::Version
110
96
  version: 3.1.0
111
97
  - !ruby/object:Gem::Dependency
112
- name: guard-rspec
98
+ name: version
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: 4.3.1
103
+ version: 1.0.0
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
- version: 4.3.1
110
+ version: 1.0.0
125
111
  - !ruby/object:Gem::Dependency
126
- name: guard-bundler
112
+ name: fuubar
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - "~>"
@@ -137,33 +123,33 @@ dependencies:
137
123
  - !ruby/object:Gem::Version
138
124
  version: 2.0.0
139
125
  - !ruby/object:Gem::Dependency
140
- name: version
126
+ name: codeclimate-test-reporter
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - "~>"
144
130
  - !ruby/object:Gem::Version
145
- version: 1.0.0
131
+ version: 0.4.1
146
132
  type: :development
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
- version: 1.0.0
138
+ version: 0.4.1
153
139
  - !ruby/object:Gem::Dependency
154
- name: fuubar
140
+ name: pullreview-coverage
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
- - - "~>"
143
+ - - ">="
158
144
  - !ruby/object:Gem::Version
159
- version: 2.0.0
145
+ version: '0'
160
146
  type: :development
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
- - - "~>"
150
+ - - ">="
165
151
  - !ruby/object:Gem::Version
166
- version: 2.0.0
152
+ version: '0'
167
153
  description: A Toolbox to help me build a board game.
168
154
  email:
169
155
  - anithri@gmail.com
@@ -176,6 +162,7 @@ files:
176
162
  - ".pullreview.yml"
177
163
  - ".rspec"
178
164
  - ".travis.yml"
165
+ - ".yardopts"
179
166
  - Gemfile
180
167
  - Guardfile
181
168
  - LICENSE.txt
@@ -250,7 +237,7 @@ rubyforge_project:
250
237
  rubygems_version: 2.4.2
251
238
  signing_key:
252
239
  specification_version: 4
253
- summary: Game Dev Toolbox.
240
+ summary: Game Board Component - Dice.
254
241
  test_files:
255
242
  - spec/gotham_dice_spec.rb
256
243
  - spec/para_dice/bag_spec.rb