hazard 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/hazard/version.rb +1 -1
- data/lib/hazard.rb +18 -0
- data/lib/rolled_dice.rb +11 -1
- data/lib/weighted_table.rb +3 -0
- 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: '08657cc882b26b86eb7897b444e125cb51799659'
|
4
|
+
data.tar.gz: b4e26bda3ada9032117860ef51f41706478f1502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23ef045fd2f8ec1548bd8e24efa5a64b2db98967d5b3c27c34676d8be30908f47ef7cd84b66111749665302927c9fd645ed2308a9464567fdfd92ead6a298570
|
7
|
+
data.tar.gz: d5715f5e44b94c8a8f6555dd4212ef94d7b5b3ee84bc78a8aef894ca9e0905beb748b920ccddcd323f7e5920e168493bac98b634b123bba48ebea179ba168c78
|
data/README.md
CHANGED
@@ -151,8 +151,7 @@ Assuming you are playing DD Next
|
|
151
151
|
|
152
152
|
## Weighted Tables
|
153
153
|
|
154
|
-
Weighted tables are object that allow to get weighted random.
|
155
|
-
Example : if you have two time foo and one time bar in your table.
|
154
|
+
Weighted tables are object that allow to get weighted random.
|
156
155
|
|
157
156
|
### If you have the weights
|
158
157
|
|
data/lib/hazard/version.rb
CHANGED
data/lib/hazard.rb
CHANGED
@@ -1,20 +1,38 @@
|
|
1
1
|
require_relative 'rolled_dice'
|
2
2
|
require_relative 'weighted_table'
|
3
3
|
|
4
|
+
# This class roll the dice.
|
5
|
+
#
|
6
|
+
# @author Cédric ZUGER
|
4
7
|
class Hazard
|
5
8
|
|
9
|
+
# Regular entry point. This is where you will go when you call Hazard.d6 for instance.
|
10
|
+
#
|
11
|
+
# @param method_name [String] the description of the dice. See help for detail.
|
12
|
+
#
|
13
|
+
# @return [Object] if detail has been asked, it will return a [RolledDice] object, otherwise it will return an [Integer] containing the sum of the dice.
|
6
14
|
def self.method_missing( method_name )
|
7
15
|
# Transform the method_name to string
|
8
16
|
method_name = method_name.to_s
|
9
17
|
self.roll_dice( method_name )
|
10
18
|
end
|
11
19
|
|
20
|
+
# From string entry point, in case you have your dice description in a database for instance.
|
21
|
+
#
|
22
|
+
# @param dice_string [String] the description of the dice. See help for detail.
|
23
|
+
#
|
24
|
+
# @return [Object] if detail has been asked, it will return a [RolledDice] object, otherwise it will return an [Integer] containing the sum of the dice.
|
12
25
|
def self.from_string( dice_string )
|
13
26
|
roll_dice( dice_string )
|
14
27
|
end
|
15
28
|
|
16
29
|
private
|
17
30
|
|
31
|
+
# Roll dice according to method name
|
32
|
+
#
|
33
|
+
# @param method_name [String] the description of the dice. See help for detail.
|
34
|
+
#
|
35
|
+
# @return [Object] if detail has been asked, it will return a [RolledDice] object, otherwise it will return an [Integer] containing the sum of the dice.
|
18
36
|
def self.roll_dice( method_name )
|
19
37
|
# Parse the method name to get how many dice and what size of dice was required
|
20
38
|
dice_match = method_name.to_s.match( /(d|r|m|s)?(\d*)d(\d+)/ )
|
data/lib/rolled_dice.rb
CHANGED
@@ -1,13 +1,23 @@
|
|
1
|
+
# This class represents the result of a roll, for people that need to work wit dice details.
|
2
|
+
#
|
3
|
+
# @author Cédric ZUGER
|
1
4
|
class RolledDice
|
2
5
|
|
3
6
|
attr_reader :result, :rolls
|
4
7
|
|
8
|
+
# Create a RolledDice object
|
9
|
+
#
|
10
|
+
# @param rolls [Array] an array of integer containing the dice rolls.
|
5
11
|
def initialize( rolls )
|
6
12
|
@rolls = rolls
|
7
13
|
@result = rolls.reduce(:+)
|
8
14
|
end
|
9
15
|
|
10
|
-
#
|
16
|
+
# Compare two rolls
|
17
|
+
#
|
18
|
+
# @param rolled_dice [RolledDice] the other RolledDice to compare
|
19
|
+
#
|
20
|
+
# @return [Boolean] the result of the comparison
|
11
21
|
def ==( rolled_dice )
|
12
22
|
@rolls == rolled_dice.rolls && @result == rolled_dice.result
|
13
23
|
end
|
data/lib/weighted_table.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hazard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cédric ZUGER
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|