rollr 1.0.4 → 1.0.99
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 +4 -4
- data/.codeclimate.yml +25 -0
- data/.rspec +0 -1
- data/.rubocop.yml +1156 -0
- data/Gemfile +1 -0
- data/README.md +17 -17
- data/lib/rollr/die.rb +12 -14
- data/lib/rollr/filters/droppers/dropper.rb +23 -0
- data/lib/rollr/filters/droppers/high_dropper.rb +7 -0
- data/lib/rollr/filters/droppers/low_dropper.rb +7 -0
- data/lib/rollr/filters/filter.rb +14 -0
- data/lib/rollr/metadata.rb +6 -0
- data/lib/rollr/roll.rb +35 -0
- data/lib/rollr/roll_report.rb +53 -0
- data/lib/rollr/version.rb +1 -1
- data/lib/rollr.rb +7 -1
- data/rollr.gemspec +1 -1
- metadata +13 -6
- data/lib/rollr/roll_result.rb +0 -42
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Rollr
|
|
2
|
-
|
|
3
|
-
Rollr
|
|
2
|
+
## Rollr has been deprecated. Please check out [Randsum](http://github.com/RANDSUM/randsum) for all your Dice-Rolling needs!
|
|
3
|
+
Rollr a gem that simulates rolling dice.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -35,29 +35,29 @@ $ irb
|
|
|
35
35
|
> d6 = Rollr::Die.new(6)
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
When you roll a `Die`, you get a `
|
|
38
|
+
When you roll a `Die`, you get a `RollReport`.
|
|
39
39
|
|
|
40
40
|
```
|
|
41
41
|
> d6.roll
|
|
42
|
-
#=> <Rollr::
|
|
42
|
+
#=> <Rollr::RollReport #hash total: 3, rolls: [3], number_of_dice: 1, die_sides: 6>
|
|
43
43
|
> d6.roll
|
|
44
|
-
#=> <Rollr::
|
|
44
|
+
#=> <Rollr::RollReport #hash total: 6, rolls: [6], number_of_dice: 1, die_sides: 6>
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
You can roll multiple dice of the same kind by passing a number to the `roll` argument.
|
|
48
48
|
|
|
49
49
|
```
|
|
50
50
|
> d6.roll(number: 3)
|
|
51
|
-
#=> <Rollr::
|
|
51
|
+
#=> <Rollr::RollReport #hash total: 9, rolls: [3, 5, 1], number_of_dice: 3, die_sides: 6>
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
### `
|
|
54
|
+
### `RollReport`s
|
|
55
55
|
```
|
|
56
56
|
> result = d6.roll(number: 3)
|
|
57
|
-
#=> <Rollr::
|
|
57
|
+
#=> <Rollr::RollReport #hash total: 14, rolls: [2, 6, 6], number_of_dice: 3, die_sides: 6>
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
The `
|
|
60
|
+
The `RollReport` has few helpful things to report about your roll.
|
|
61
61
|
|
|
62
62
|
The `#total` method represents the sum total of the dice that were rolled:
|
|
63
63
|
|
|
@@ -87,15 +87,15 @@ result.die_sides
|
|
|
87
87
|
#=> 6
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
#### Manipulating `
|
|
90
|
+
#### Manipulating `RollReport`s
|
|
91
91
|
|
|
92
|
-
Roll results can be further manipulated after their original creation. To facilitate popular use-cases for Dice rolling, `
|
|
92
|
+
Roll results can be further manipulated after their original creation. To facilitate popular use-cases for Dice rolling, `RollReport`s also include public `#drop_lowest` and `#drop_highest` methods.
|
|
93
93
|
|
|
94
|
-
`#drop_lowest` returns a new `
|
|
94
|
+
`#drop_lowest` returns a new `RollReport` without the lowest numerical die roll.
|
|
95
95
|
|
|
96
96
|
```
|
|
97
97
|
> result = d6.roll(number: 4)
|
|
98
|
-
#=> <Rollr::
|
|
98
|
+
#=> <Rollr::RollReport #hash total: 14, rolls: [3, 1, 4, 6], number_of_dice: 4, die_sides: 6>
|
|
99
99
|
|
|
100
100
|
> result.rolls
|
|
101
101
|
#=> [3, 1, 4, 6]
|
|
@@ -104,7 +104,7 @@ Roll results can be further manipulated after their original creation. To facili
|
|
|
104
104
|
#=> 14
|
|
105
105
|
|
|
106
106
|
> new_result = result.drop_lowest
|
|
107
|
-
#=> <Rollr::
|
|
107
|
+
#=> <Rollr::RollReport #hash total: 13, rolls: [3, 4, 6], number_of_dice: 3, die_sides: 6>
|
|
108
108
|
|
|
109
109
|
> new_result.rolls
|
|
110
110
|
#=> [3, 4, 6]
|
|
@@ -117,7 +117,7 @@ Similarly, `#drop_highest` will remove the highest number in the `rolls` array.
|
|
|
117
117
|
|
|
118
118
|
```
|
|
119
119
|
> new_result = result.drop_highest
|
|
120
|
-
#=> <Rollr::
|
|
120
|
+
#=> <Rollr::RollReport #hash total: 8, rolls: [3, 1, 4], number_of_dice: 3, die_sides: 6>
|
|
121
121
|
|
|
122
122
|
> new_result.rolls
|
|
123
123
|
#=> [3, 1, 4]
|
|
@@ -145,11 +145,11 @@ Rollr comes pre-packaged with several shortcuts for popular Die sizes:
|
|
|
145
145
|
```
|
|
146
146
|
#D20
|
|
147
147
|
> result = Rollr::D20.roll
|
|
148
|
-
#=> <Rollr::
|
|
148
|
+
#=> <Rollr::RollReport #hash total: 18, rolls: [18], number_of_dice: 1, die_sides: 20>
|
|
149
149
|
|
|
150
150
|
#D12
|
|
151
151
|
> result = Rollr::D12.roll
|
|
152
|
-
#=> <Rollr::
|
|
152
|
+
#=> <Rollr::RollReport #hash total: 6, rolls: [6], number_of_dice: 1, die_sides: 12>
|
|
153
153
|
|
|
154
154
|
#D2-6, D8, and D10!
|
|
155
155
|
```
|
data/lib/rollr/die.rb
CHANGED
|
@@ -2,27 +2,25 @@ require 'securerandom'
|
|
|
2
2
|
|
|
3
3
|
module Rollr
|
|
4
4
|
class Die
|
|
5
|
-
|
|
5
|
+
ZERO_INDEX_FIXER = 1
|
|
6
|
+
attr_accessor :sides, :randomizer
|
|
6
7
|
|
|
7
|
-
def initialize(sides)
|
|
8
|
+
def initialize(sides, randomizer: SecureRandom)
|
|
8
9
|
@sides = sides
|
|
10
|
+
@randomizer = randomizer
|
|
9
11
|
end
|
|
10
12
|
|
|
11
|
-
def roll(
|
|
12
|
-
Rollr::
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
def roll(quantity = 1)
|
|
14
|
+
Rollr::RollReport.new(
|
|
15
|
+
Rollr::Roll.new(
|
|
16
|
+
quantity: quantity,
|
|
17
|
+
die: self
|
|
18
|
+
)
|
|
15
19
|
)
|
|
16
20
|
end
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def single_roll
|
|
21
|
-
SecureRandom.random_number(sides).to_i + 1
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def rolls(number)
|
|
25
|
-
(1..number).map { single_roll }
|
|
22
|
+
def simple_roll
|
|
23
|
+
randomizer.random_number(sides).to_i + ZERO_INDEX_FIXER
|
|
26
24
|
end
|
|
27
25
|
end
|
|
28
26
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Rollr
|
|
2
|
+
class Dropper < Filter
|
|
3
|
+
|
|
4
|
+
def self.dropper_for(quantity:,extremity:, rolls:)
|
|
5
|
+
Object.const_get(
|
|
6
|
+
"Rollr::#{extremity.to_s.gsub("est","").capitalize}Dropper"
|
|
7
|
+
).new(quantity: quantity, rolls: rolls)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def filter
|
|
11
|
+
ordered.first(remainder)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def ordered
|
|
15
|
+
raise NotImplementedError
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def remainder
|
|
19
|
+
rolls.length - quantity
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/rollr/roll.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Rollr
|
|
2
|
+
class Roll
|
|
3
|
+
attr_reader :die, :quantity, :sides, :result
|
|
4
|
+
|
|
5
|
+
def initialize(die:, quantity:, result: nil)
|
|
6
|
+
@die = die
|
|
7
|
+
@quantity = quantity
|
|
8
|
+
@sides = die.sides
|
|
9
|
+
@result = result || roll!
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def drop(quantity:,extremity:)
|
|
13
|
+
return new_roll_with(
|
|
14
|
+
result: Dropper.dropper_for(
|
|
15
|
+
quantity: quantity,
|
|
16
|
+
extremity: extremity,
|
|
17
|
+
rolls: result
|
|
18
|
+
).filter
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
def new_roll_with(result:)
|
|
24
|
+
return Roll.new(
|
|
25
|
+
die: die,
|
|
26
|
+
quantity: quantity,
|
|
27
|
+
result: result
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def roll!
|
|
32
|
+
(1..quantity).map { die.simple_roll }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Rollr
|
|
2
|
+
class RollReport
|
|
3
|
+
|
|
4
|
+
def initialize(roll)
|
|
5
|
+
@roll = roll
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def to_i
|
|
9
|
+
total
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def sides
|
|
13
|
+
die.sides
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def die
|
|
17
|
+
roll.die
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def rolls
|
|
21
|
+
@_rolls ||= roll.result
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def total
|
|
25
|
+
@_total ||= rolls.inject(:+)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def quantity
|
|
29
|
+
@_quantity ||= rolls.count
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def drop(quantity:, extremity:)
|
|
33
|
+
return RollReport.new(
|
|
34
|
+
roll.drop(quantity: quantity, extremity: extremity)
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def drop_lowest(quantity = 1)
|
|
39
|
+
return RollReport.new(
|
|
40
|
+
roll.drop(quantity: quantity, extremity: :lowest)
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def drop_highest(quantity = 1)
|
|
45
|
+
return RollReport.new(
|
|
46
|
+
roll.drop(quantity: quantity, extremity: :highest)
|
|
47
|
+
)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
attr_reader :roll
|
|
52
|
+
end
|
|
53
|
+
end
|
data/lib/rollr/version.rb
CHANGED
data/lib/rollr.rb
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
require "rollr/version"
|
|
2
|
+
require "rollr/filters/filter"
|
|
3
|
+
require "rollr/filters/droppers/dropper"
|
|
4
|
+
require "rollr/filters/droppers/high_dropper"
|
|
5
|
+
require "rollr/filters/droppers/low_dropper"
|
|
6
|
+
require "rollr/roll"
|
|
2
7
|
require "rollr/die"
|
|
3
|
-
require "rollr/
|
|
8
|
+
require "rollr/roll_report"
|
|
4
9
|
|
|
5
10
|
module Rollr
|
|
11
|
+
warn "Rollr is deprecated. Please use 'randsum' Instead! (RANDSUM/randsum on github)"
|
|
6
12
|
|
|
7
13
|
D2 = Die.new(2)
|
|
8
14
|
D3 = Die.new(3)
|
data/rollr.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.authors = ["Alex Jarvis"]
|
|
10
10
|
spec.email = ["alxjrvs@gmail.com"]
|
|
11
11
|
spec.summary = %q{Random Numbers, With Style.}
|
|
12
|
-
spec.description = %q{Rollr
|
|
12
|
+
spec.description = %q{Rollr has been deprecated, and moved to RANDSUM/randsum. Please use the randsum gem!}
|
|
13
13
|
spec.homepage = "http://www.github.com/alxjrvs/rollr"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rollr
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.99
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex Jarvis
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-11-
|
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -66,17 +66,18 @@ dependencies:
|
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: 0.10.3
|
|
69
|
-
description: Rollr
|
|
70
|
-
|
|
71
|
-
numbers securely and succinctly.
|
|
69
|
+
description: Rollr has been deprecated, and moved to RANDSUM/randsum. Please use the
|
|
70
|
+
randsum gem!
|
|
72
71
|
email:
|
|
73
72
|
- alxjrvs@gmail.com
|
|
74
73
|
executables: []
|
|
75
74
|
extensions: []
|
|
76
75
|
extra_rdoc_files: []
|
|
77
76
|
files:
|
|
77
|
+
- ".codeclimate.yml"
|
|
78
78
|
- ".gitignore"
|
|
79
79
|
- ".rspec"
|
|
80
|
+
- ".rubocop.yml"
|
|
80
81
|
- ".ruby-version"
|
|
81
82
|
- ".travis.yml"
|
|
82
83
|
- CODE_OF_CONDUCT.md
|
|
@@ -90,7 +91,13 @@ files:
|
|
|
90
91
|
- bin/setup
|
|
91
92
|
- lib/rollr.rb
|
|
92
93
|
- lib/rollr/die.rb
|
|
93
|
-
- lib/rollr/
|
|
94
|
+
- lib/rollr/filters/droppers/dropper.rb
|
|
95
|
+
- lib/rollr/filters/droppers/high_dropper.rb
|
|
96
|
+
- lib/rollr/filters/droppers/low_dropper.rb
|
|
97
|
+
- lib/rollr/filters/filter.rb
|
|
98
|
+
- lib/rollr/metadata.rb
|
|
99
|
+
- lib/rollr/roll.rb
|
|
100
|
+
- lib/rollr/roll_report.rb
|
|
94
101
|
- lib/rollr/version.rb
|
|
95
102
|
- rollr.gemspec
|
|
96
103
|
homepage: http://www.github.com/alxjrvs/rollr
|
data/lib/rollr/roll_result.rb
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
module Rollr
|
|
2
|
-
class RollResult
|
|
3
|
-
attr_accessor :rolls, :sides
|
|
4
|
-
|
|
5
|
-
def initialize(sides:, rolls:)
|
|
6
|
-
@sides = sides
|
|
7
|
-
@rolls = rolls
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def die_sides
|
|
11
|
-
@sides
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def total
|
|
15
|
-
@_total ||= rolls.inject(:+)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def number_of_dice
|
|
19
|
-
@_number_of_dice ||= rolls.count
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def drop_lowest(num = 1)
|
|
23
|
-
return RollResult.new(
|
|
24
|
-
sides: sides,
|
|
25
|
-
rolls: sorted_rolls.last(rolls.length - num)
|
|
26
|
-
)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def drop_highest(num = 1)
|
|
30
|
-
return RollResult.new(
|
|
31
|
-
sides: sides,
|
|
32
|
-
rolls: sorted_rolls.first(rolls.length - num)
|
|
33
|
-
)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
def sorted_rolls
|
|
39
|
-
rolls.sort
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|