hazard 1.0.1 → 1.0.2
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 +21 -10
- data/hazard.gemspec +2 -2
- data/lib/hazard/version.rb +1 -1
- data/lib/hazard.rb +14 -14
- data/lib/{rolled_dices.rb → rolled_dice.rb} +3 -3
- data/test/hazard_test.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5017ca137a9ac74552972f1301a18878035016cf
|
4
|
+
data.tar.gz: 6ff5453dda46882f844cca27cb2ca0f964588f61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed5948b03b7f4f69860eb84954ce03582520402116603eb3d2b8507450e7b08daed645c7398282a79b0cf86fad93b9ddafb899b8b3960688fe49cb8a2b91f100
|
7
|
+
data.tar.gz: 7e89790f4dd30f8f1414ec41c6b930bf2188dbd97186c1d08fe0f64a532dd8955fba85375999c4755f1774a597fef15eb963d2101d64f035be013e5c61652920
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# Hazard
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/hazard)
|
4
|
+
[](https://travis-ci.org/czuger/hazard)
|
4
5
|
[](https://codeclimate.com/github/czuger/hazard)
|
5
6
|
[](https://codeclimate.com/github/czuger/hazard/coverage)
|
6
7
|
|
7
|
-
Hazard is a very simple
|
8
|
+
Hazard is a very simple dice library for ruby (see [usage](#usage)).
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
@@ -28,10 +29,10 @@ If needed :
|
|
28
29
|
|
29
30
|
## Usage
|
30
31
|
|
31
|
-
Roll a simple
|
32
|
+
**Roll a simple die**
|
32
33
|
|
33
34
|
>> Hazard.d<n> # where n is an number
|
34
|
-
=> Roll a n-sided
|
35
|
+
=> Roll a n-sided die
|
35
36
|
|
36
37
|
Examples :
|
37
38
|
|
@@ -45,10 +46,10 @@ Examples :
|
|
45
46
|
=> 38
|
46
47
|
|
47
48
|
|
48
|
-
Roll multiple
|
49
|
+
**Roll multiple dice**
|
49
50
|
|
50
51
|
>> Hazard.r<m>d<n> # where m and n are numbers
|
51
|
-
=> Roll m n-sided
|
52
|
+
=> Roll m n-sided dice and return the sum
|
52
53
|
|
53
54
|
Examples :
|
54
55
|
|
@@ -62,10 +63,10 @@ Examples :
|
|
62
63
|
=> 356
|
63
64
|
|
64
65
|
|
65
|
-
Roll
|
66
|
+
**Roll dice and get the details**
|
66
67
|
|
67
68
|
>> Hazard.s<m>d<n> # where m and n are numbers
|
68
|
-
=> Roll m n-sided
|
69
|
+
=> Roll m n-sided dice and return a RolledDice object
|
69
70
|
|
70
71
|
Examples :
|
71
72
|
|
@@ -73,17 +74,27 @@ Examples :
|
|
73
74
|
=> [1, 6]
|
74
75
|
|
75
76
|
>> Hazard.s2d6.result
|
77
|
+
=> 3
|
78
|
+
|
79
|
+
# Caution, each time you call Hazard it will reroll the dice
|
80
|
+
# If you want to work on result and rolls, save them in a variable
|
81
|
+
>> roll = Hazard.s2d6
|
82
|
+
|
83
|
+
>> roll.rolls
|
84
|
+
=> [1, 6]
|
85
|
+
|
86
|
+
>> roll.result
|
76
87
|
=> 7
|
77
88
|
|
78
89
|
# Under the hood
|
79
90
|
>> Hazard.s2d6
|
80
|
-
=> #<
|
91
|
+
=> #<RolledDice:0x007f62e55a0010 @rolls=[1, 6], @result=7>
|
81
92
|
|
82
|
-
Some real cases
|
93
|
+
**Some real cases**
|
83
94
|
|
84
95
|
# Assuming you are playing DD Next
|
85
96
|
|
86
|
-
# You may want to roll 2 d20
|
97
|
+
# You may want to roll 2 d20 dice with advantage (take the greatest)
|
87
98
|
# This will rolls 2 d20, get the rolls and get the best of them
|
88
99
|
|
89
100
|
>> Hazard.s2d20.rolls.max
|
data/hazard.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['ced']
|
11
11
|
spec.email = ['zuger.cedric@gmail.com']
|
12
12
|
|
13
|
-
spec.summary = '
|
14
|
-
spec.description = 'A very simple
|
13
|
+
spec.summary = 'Dice library for ruby'
|
14
|
+
spec.description = 'A very simple dice library for ruby'
|
15
15
|
spec.homepage = 'https://github.com/czuger/hazard'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
data/lib/hazard/version.rb
CHANGED
data/lib/hazard.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'rolled_dice'
|
2
2
|
|
3
3
|
class Hazard
|
4
4
|
|
@@ -14,26 +14,26 @@ class Hazard
|
|
14
14
|
splitted_result = true
|
15
15
|
end
|
16
16
|
|
17
|
-
# Parse the method name to get how many
|
18
|
-
|
17
|
+
# Parse the method name to get how many dice and what size of dice was required
|
18
|
+
dice_match = method_name.to_s.match( /(\d*)d(\d+)/ )
|
19
19
|
# Raise an error if match fail
|
20
|
-
raise "Method mising : #{method_name}" unless
|
20
|
+
raise "Method mising : #{method_name}" unless dice_match
|
21
21
|
|
22
|
-
# Get the
|
23
|
-
|
22
|
+
# Get the dice amount
|
23
|
+
dice_amount = dice_match[1].to_i
|
24
24
|
# If no amount is given then the amount is 1
|
25
|
-
|
26
|
-
# Get the type of
|
27
|
-
dice_type =
|
25
|
+
dice_amount = 1 if dice_amount == 0
|
26
|
+
# Get the type of dice
|
27
|
+
dice_type = dice_match[2].to_i
|
28
28
|
|
29
|
-
# Rolls the
|
30
|
-
rolls = (1..
|
29
|
+
# Rolls the dice
|
30
|
+
rolls = (1..dice_amount).map{ Kernel.rand( 1..dice_type ) }
|
31
31
|
|
32
|
-
# Unless splitted_result was requested, return the sum of the rolled
|
32
|
+
# Unless splitted_result was requested, return the sum of the rolled dice
|
33
33
|
return rolls.reduce(:+) unless splitted_result
|
34
34
|
|
35
|
-
# Return a
|
36
|
-
|
35
|
+
# Return a RolledDice otherwise
|
36
|
+
RolledDice.new(rolls )
|
37
37
|
|
38
38
|
end
|
39
39
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class RolledDice
|
2
2
|
|
3
3
|
attr_reader :result, :rolls
|
4
4
|
|
@@ -8,8 +8,8 @@ class RolledDices
|
|
8
8
|
end
|
9
9
|
|
10
10
|
# Required for tests
|
11
|
-
def ==(
|
12
|
-
@rolls ==
|
11
|
+
def ==( rolled_dice )
|
12
|
+
@rolls == rolled_dice.rolls && @result == rolled_dice.result
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
data/test/hazard_test.rb
CHANGED
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class HazardTest < Minitest::Test
|
4
4
|
|
5
|
-
def
|
5
|
+
def test_dice
|
6
6
|
|
7
7
|
Kernel.stubs( :rand ).returns( 6 )
|
8
8
|
|
@@ -11,7 +11,7 @@ class HazardTest < Minitest::Test
|
|
11
11
|
assert_equal 12, Hazard.r2d6
|
12
12
|
assert_equal 12, Hazard._2d6
|
13
13
|
|
14
|
-
assert_equal
|
14
|
+
assert_equal RolledDice.new([6, 6 ] ), Hazard.s2d6
|
15
15
|
|
16
16
|
end
|
17
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hazard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ced
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
-
description: A very simple
|
55
|
+
description: A very simple dice library for ruby
|
56
56
|
email:
|
57
57
|
- zuger.cedric@gmail.com
|
58
58
|
executables: []
|
@@ -69,7 +69,7 @@ files:
|
|
69
69
|
- hazard.gemspec
|
70
70
|
- lib/hazard.rb
|
71
71
|
- lib/hazard/version.rb
|
72
|
-
- lib/
|
72
|
+
- lib/rolled_dice.rb
|
73
73
|
- test/hazard_test.rb
|
74
74
|
- test/test_helper.rb
|
75
75
|
homepage: https://github.com/czuger/hazard
|
@@ -95,7 +95,7 @@ rubyforge_project:
|
|
95
95
|
rubygems_version: 2.4.8
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
|
-
summary:
|
98
|
+
summary: Dice library for ruby
|
99
99
|
test_files:
|
100
100
|
- test/hazard_test.rb
|
101
101
|
- test/test_helper.rb
|