hazard 1.0.3 → 1.0.4
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/.ruby-version +1 -0
- data/.travis.yml +25 -3
- data/README.md +22 -23
- data/lib/hazard/version.rb +1 -1
- data/lib/hazard.rb +11 -14
- data/test/hazard_test.rb +3 -0
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d73a6ac407a313337a1309b8f85680c2acdf9a36
|
4
|
+
data.tar.gz: f26d0073ed98e7d10483815e6b16f6456e582142
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b6aa19cf68606574fca81bbb5c3242fbabc44833806078de8a883de43fba72c16df8a10f42b163a0c18e829d70d873bb3e3450634cf30115c08254e43fe4fa4
|
7
|
+
data.tar.gz: 4decd66c91587ad5a1eba94d94d575432c874589801fd9a087e7ba88c50930e6feb1ca1d11a8dfe8d40bdf7cbb221393d0dcc531b6785febcb02f915bbbcd960
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.2
|
data/.travis.yml
CHANGED
@@ -1,5 +1,27 @@
|
|
1
|
-
sudo: false
|
1
|
+
#sudo: false
|
2
|
+
|
3
|
+
#before_install: gem install bundler -v 1.13.6
|
4
|
+
|
5
|
+
env:
|
6
|
+
global:
|
7
|
+
- CC_TEST_REPORTER_ID=909815ccc68b9e9eea2388daa1b7d8edfa32a4dc013c367ea2ca3442d1742964
|
8
|
+
|
2
9
|
language: ruby
|
3
10
|
rvm:
|
4
|
-
- 2.
|
5
|
-
|
11
|
+
- 2.5
|
12
|
+
- 2.4
|
13
|
+
- 2.3
|
14
|
+
- 2.2
|
15
|
+
- 2.1
|
16
|
+
- 2.0
|
17
|
+
|
18
|
+
before_script:
|
19
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
20
|
+
- chmod +x ./cc-test-reporter
|
21
|
+
- ./cc-test-reporter before-build
|
22
|
+
|
23
|
+
script:
|
24
|
+
- bundle exec rake
|
25
|
+
|
26
|
+
after_script:
|
27
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/README.md
CHANGED
@@ -39,10 +39,10 @@ Examples :
|
|
39
39
|
>> Hazard.d6
|
40
40
|
=> 2
|
41
41
|
|
42
|
-
Hazard.d8
|
42
|
+
>> Hazard.d8
|
43
43
|
=> 4
|
44
44
|
|
45
|
-
Hazard.d42
|
45
|
+
>> Hazard.d42
|
46
46
|
=> 38
|
47
47
|
|
48
48
|
|
@@ -50,19 +50,29 @@ Examples :
|
|
50
50
|
|
51
51
|
>> Hazard.r<m>d<n> # where m and n are numbers
|
52
52
|
=> Roll m n-sided dice and return the sum
|
53
|
+
|
54
|
+
# You can also use
|
55
|
+
>> Hazard.m<m>d<n> # where m and n are numbers
|
56
|
+
>> Hazard.d<m>d<n> # where m and n are numbers
|
53
57
|
|
54
58
|
Examples :
|
55
59
|
|
56
|
-
Hazard.r2d6
|
57
|
-
|
60
|
+
>> Hazard.r2d6
|
61
|
+
=> 4
|
58
62
|
|
59
|
-
Hazard.r4d8
|
60
|
-
|
63
|
+
>> Hazard.r4d8
|
64
|
+
=> 12
|
61
65
|
|
62
|
-
Hazard.r48d42
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
+
>> Hazard.r48d42
|
67
|
+
=> 356
|
68
|
+
|
69
|
+
>> Hazard.m2d6
|
70
|
+
=> 6
|
71
|
+
|
72
|
+
>> Hazard.d2d6
|
73
|
+
=> 8
|
74
|
+
|
75
|
+
|
66
76
|
**Roll dice and get the details**
|
67
77
|
|
68
78
|
>> Hazard.s<m>d<n> # where m and n are numbers
|
@@ -96,32 +106,21 @@ Examples :
|
|
96
106
|
|
97
107
|
# You may want to roll 2 d20 dice with advantage (take the greatest)
|
98
108
|
# This will rolls 2 d20, get the rolls and get the best of them
|
99
|
-
|
100
109
|
>> Hazard.s2d20.rolls.max
|
101
110
|
=> 19
|
102
111
|
|
103
112
|
# Obviously a disadvantage is
|
104
|
-
|
105
113
|
>> Hazard.s2d20.rolls.min
|
106
114
|
=> 13
|
107
115
|
|
108
116
|
# Maybe you want to roll with an advantage and make the check (because you are as lazy as me)
|
109
|
-
|
110
117
|
>> Hazard.s2d20.rolls.max > 12
|
111
118
|
=> true or false
|
112
119
|
|
113
120
|
# Should you have the Elemental Adept feat, which mean that you treat all 1 as 2
|
114
121
|
# If you cast a fireball, this will do the trick :
|
115
|
-
|
116
|
-
|
117
|
-
=> 13
|
118
|
-
|
119
|
-
|
120
|
-
## Development
|
121
|
-
|
122
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
123
|
-
|
124
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
122
|
+
>> Hazard.s8d6.rolls.map{ |d| d == 1 ? 2 : d }.reduce(:+)
|
123
|
+
=> 24
|
125
124
|
|
126
125
|
## Contributing
|
127
126
|
|
data/lib/hazard/version.rb
CHANGED
data/lib/hazard.rb
CHANGED
@@ -7,34 +7,31 @@ class Hazard
|
|
7
7
|
# Transform the method_name to string
|
8
8
|
method_name = method_name.to_s
|
9
9
|
|
10
|
-
# If first character is 's'
|
11
|
-
if method_name[0] == 's'
|
12
|
-
method_name = method_name[1..-1]
|
13
|
-
# Then we will return a splitted result
|
14
|
-
splitted_result = true
|
15
|
-
end
|
16
|
-
|
17
10
|
# 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+)/ )
|
11
|
+
dice_match = method_name.to_s.match( /(d|r|m|s)?(\d*)d(\d+)/ )
|
19
12
|
# Raise an error if match fail
|
20
13
|
raise "Method mising : #{method_name}" unless dice_match
|
21
14
|
|
15
|
+
# Get the roll type
|
16
|
+
roll_type = dice_match[1]
|
17
|
+
splited_result = true if roll_type == 's'
|
18
|
+
|
22
19
|
# Get the dice amount
|
23
|
-
dice_amount = dice_match[
|
20
|
+
dice_amount = dice_match[2].to_i
|
24
21
|
# If no amount is given then the amount is 1
|
25
22
|
dice_amount = 1 if dice_amount == 0
|
26
23
|
# Get the type of dice
|
27
|
-
dice_type = dice_match[
|
24
|
+
dice_type = dice_match[3].to_i
|
28
25
|
|
29
26
|
# Rolls the dice
|
30
|
-
rolls = (1..dice_amount).map{ Kernel.rand( 1..dice_type ) }
|
27
|
+
rolls = ( 1..dice_amount ).map{ Kernel.rand( 1..dice_type ) }
|
31
28
|
|
32
29
|
# Unless splitted_result was requested, return the sum of the rolled dice
|
33
|
-
return rolls.reduce(:+) unless
|
30
|
+
return rolls.reduce(:+) unless splited_result
|
34
31
|
|
35
32
|
# Return a RolledDice otherwise
|
36
|
-
RolledDice.new(rolls )
|
33
|
+
RolledDice.new( rolls )
|
37
34
|
|
38
35
|
end
|
39
36
|
|
40
|
-
end
|
37
|
+
end
|
data/test/hazard_test.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
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.4
|
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:
|
11
|
+
date: 2018-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.13'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.13'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '5.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
55
|
description: A very simple dice library for ruby
|
@@ -59,8 +59,9 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .
|
62
|
+
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
64
|
+
- ".travis.yml"
|
64
65
|
- CODE_OF_CONDUCT.md
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
@@ -82,17 +83,17 @@ require_paths:
|
|
82
83
|
- lib
|
83
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
85
|
requirements:
|
85
|
-
- -
|
86
|
+
- - ">="
|
86
87
|
- !ruby/object:Gem::Version
|
87
88
|
version: '0'
|
88
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
90
|
requirements:
|
90
|
-
- -
|
91
|
+
- - ">="
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
95
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.6.13
|
96
97
|
signing_key:
|
97
98
|
specification_version: 4
|
98
99
|
summary: Dice library for ruby
|