rollr 1.0.2 → 1.0.3
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/README.md +59 -30
- data/lib/rollr/die.rb +6 -6
- data/lib/rollr/roll_result.rb +23 -3
- data/lib/rollr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abb626fa239a16084db24fe697c926e487125b85
|
4
|
+
data.tar.gz: f073bf80d411236ce05498f09ce15f16217b5715
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c0f428e1589a7d00a8d0d2ce82b433101f024a2ef322990a4492b74004e37b6c62fcf14743f5396804af5abb0228b6de92b836e06c765624c308d7604333225
|
7
|
+
data.tar.gz: 774957eb15c28d9fd4257b888b32f01efa012390e907078aa27783065575fbf162dc9df0636034be5aa471c3439498081c371d484e6fe410fc13dd25128472e2
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ $ irb
|
|
35
35
|
> d6 = Rollr::Die.new(6)
|
36
36
|
```
|
37
37
|
|
38
|
-
When you roll a `Die`, you get a `RollResult`.
|
38
|
+
When you roll a `Die`, you get a `RollResult`.
|
39
39
|
|
40
40
|
```
|
41
41
|
> d6.roll
|
@@ -44,7 +44,7 @@ When you roll a `Die`, you get a `RollResult`.
|
|
44
44
|
#=> <Rollr::RollResult #hash total: 6, rolls: [6], number_of_dice: 1, die_sides: 6>
|
45
45
|
```
|
46
46
|
|
47
|
-
You can roll multiple dice of the same kind by passing a number to the `roll` argument with the `number` keyword argument.
|
47
|
+
You can roll multiple dice of the same kind by passing a number to the `roll` argument with the `number` keyword argument.
|
48
48
|
|
49
49
|
```
|
50
50
|
> d6.roll(number: 3)
|
@@ -57,27 +57,27 @@ You can roll multiple dice of the same kind by passing a number to the `roll` ar
|
|
57
57
|
#=> <Rollr::RollResult #hash total: 14, rolls: [2, 6, 6], number_of_dice: 3, die_sides: 6>
|
58
58
|
```
|
59
59
|
|
60
|
-
The `RollResult` has few helpful things to report about your roll.
|
60
|
+
The `RollResult` has few helpful things to report about your roll.
|
61
61
|
|
62
|
-
The `#total` method represents the sum total of the dice that were rolled:
|
62
|
+
The `#total` method represents the sum total of the dice that were rolled:
|
63
63
|
|
64
64
|
```
|
65
65
|
> result.total
|
66
66
|
#=> 14
|
67
67
|
```
|
68
68
|
|
69
|
-
The `#rolls` array, which reports the individual results of any dice rolled:
|
69
|
+
The `#rolls` array, which reports the individual results of any dice rolled:
|
70
70
|
|
71
71
|
```
|
72
72
|
> result.rolls
|
73
73
|
#=> [2, 6, 6]
|
74
74
|
```
|
75
75
|
|
76
|
-
`#number_of_dice` tells you how many dice were rolled this time:
|
76
|
+
`#number_of_dice` tells you how many dice were rolled this time:
|
77
77
|
|
78
78
|
```
|
79
79
|
result.number_of_dice
|
80
|
-
#=> 3
|
80
|
+
#=> 3
|
81
81
|
```
|
82
82
|
|
83
83
|
`#die_sides` reports the number of sides on the dice rolled in this result:
|
@@ -87,6 +87,57 @@ result.die_sides
|
|
87
87
|
#=> 6
|
88
88
|
```
|
89
89
|
|
90
|
+
#### Manipulating `RollResult`s
|
91
|
+
|
92
|
+
Roll results can be further manipulated after their original creation. To facilitate popular use-cases for Dice rolling, `RollResult`s also include public `#drop_lowest` and `#drop_highest` methods.
|
93
|
+
|
94
|
+
`#drop_lowest` returns a new `RollResult` without the lowest numerical die roll.
|
95
|
+
|
96
|
+
```
|
97
|
+
> result = d6.roll(number: 4)
|
98
|
+
#=> <Rollr::RollResult #hash total: 14, rolls: [3, 1, 4, 6], number_of_dice: 4, die_sides: 6>
|
99
|
+
|
100
|
+
> result.rolls
|
101
|
+
#=> [3, 1, 4, 6]
|
102
|
+
|
103
|
+
> result.total
|
104
|
+
#=> 14
|
105
|
+
|
106
|
+
> new_result = result.drop_lowest
|
107
|
+
#=> <Rollr::RollResult #hash total: 13, rolls: [3, 4, 6], number_of_dice: 3, die_sides: 6>
|
108
|
+
|
109
|
+
> new_result.rolls
|
110
|
+
#=> [3, 4, 6]
|
111
|
+
|
112
|
+
> new_result.total
|
113
|
+
#=> 13
|
114
|
+
```
|
115
|
+
|
116
|
+
Similarly, `#drop_highest` will remove the highest number in the `rolls` array.
|
117
|
+
|
118
|
+
```
|
119
|
+
> new_result = result.drop_highest
|
120
|
+
#=> <Rollr::RollResult #hash total: 8, rolls: [3, 1, 4], number_of_dice: 3, die_sides: 6>
|
121
|
+
|
122
|
+
> new_result.rolls
|
123
|
+
#=> [3, 1, 4]
|
124
|
+
|
125
|
+
> new_result.total
|
126
|
+
#=> 8
|
127
|
+
```
|
128
|
+
|
129
|
+
Both `#drop_lowest` and `#drop_highest` can also take an optional integer argument.
|
130
|
+
|
131
|
+
```
|
132
|
+
> new_result = result.drop_highest(2)
|
133
|
+
|
134
|
+
> new_result.rolls
|
135
|
+
#=> [3, 1]
|
136
|
+
|
137
|
+
> new_result.total
|
138
|
+
#=> 4
|
139
|
+
```
|
140
|
+
|
90
141
|
### Dice Constants
|
91
142
|
|
92
143
|
Rollr comes pre-packaged with several shortcuts for popular Die sizes:
|
@@ -100,29 +151,7 @@ Rollr comes pre-packaged with several shortcuts for popular Die sizes:
|
|
100
151
|
> result = Rollr::D12.roll
|
101
152
|
#=> <Rollr::RollResult #hash total: 6, rolls: [6], number_of_dice: 1, die_sides: 12>
|
102
153
|
|
103
|
-
#D10
|
104
|
-
> result = Rollr::D10.roll
|
105
|
-
#=> <Rollr::RollResult #hash total: 6, rolls: [6], number_of_dice: 1, die_sides: 12>
|
106
|
-
|
107
|
-
#D8
|
108
|
-
> result = Rollr::D8.roll
|
109
|
-
#=> <Rollr::RollResult #hash total: 6, rolls: [6], number_of_dice: 1, die_sides: 12>
|
110
|
-
|
111
|
-
#D6
|
112
|
-
> result = Rollr::D6.roll
|
113
|
-
#=> <Rollr::RollResult #hash total: 6, rolls: [6], number_of_dice: 1, die_sides: 12>
|
114
|
-
|
115
|
-
#D4
|
116
|
-
> result = Rollr::D4.roll
|
117
|
-
#=> <Rollr::RollResult #hash total: 6, rolls: [6], number_of_dice: 1, die_sides: 12>
|
118
|
-
|
119
|
-
#D3
|
120
|
-
> result = Rollr::D3.roll
|
121
|
-
#=> <Rollr::RollResult #hash total: 6, rolls: [6], number_of_dice: 1, die_sides: 12>
|
122
|
-
|
123
|
-
#D2
|
124
|
-
> result = Rollr::D2.roll
|
125
|
-
#=> <Rollr::RollResult #hash total: 6, rolls: [6], number_of_dice: 1, die_sides: 12>
|
154
|
+
#D2-6, D8, and D10!
|
126
155
|
```
|
127
156
|
|
128
157
|
## Development
|
data/lib/rollr/die.rb
CHANGED
@@ -6,23 +6,23 @@ module Rollr
|
|
6
6
|
|
7
7
|
def initialize(sides)
|
8
8
|
@sides = sides
|
9
|
-
end
|
9
|
+
end
|
10
10
|
|
11
11
|
def roll(number: 1)
|
12
12
|
Rollr::RollResult.new(
|
13
|
-
rolls:
|
13
|
+
rolls: rolls(number),
|
14
14
|
sides: sides
|
15
15
|
)
|
16
|
-
end
|
16
|
+
end
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def single_roll
|
21
|
-
SecureRandom.random_number(sides) + 1
|
21
|
+
SecureRandom.random_number(sides).to_i + 1
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def rolls(number)
|
25
25
|
(1..number).map { single_roll }
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
28
28
|
end
|
data/lib/rollr/roll_result.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Rollr
|
2
2
|
class RollResult
|
3
|
-
attr_accessor :rolls
|
3
|
+
attr_accessor :rolls, :sides
|
4
4
|
|
5
5
|
def initialize(sides:, rolls:)
|
6
6
|
@sides = sides
|
7
7
|
@rolls = rolls
|
8
|
-
end
|
8
|
+
end
|
9
9
|
|
10
10
|
def die_sides
|
11
11
|
@sides
|
@@ -18,5 +18,25 @@ module Rollr
|
|
18
18
|
def number_of_dice
|
19
19
|
@_number_of_dice ||= rolls.count
|
20
20
|
end
|
21
|
-
|
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
|
22
42
|
end
|
data/lib/rollr/version.rb
CHANGED
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.3
|
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
|
+
date: 2016-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|