dicebag 3.3.0 → 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dicebag +13 -2
- data/lib/dicebag/normalize.rb +10 -2
- data/lib/dicebag/parser.rb +2 -2
- data/lib/dicebag/roll_part.rb +2 -2
- data/lib/dicebag/roll_part_string.rb +2 -2
- data/lib/dicebag/transform.rb +4 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f932f637949ae902d7a548f3f840bbac83eb889986468e02c149b23800e00b04
|
4
|
+
data.tar.gz: 21e477659ac97f48eba24053a5a2e07852dbac9f2220a84474d04b4624e96395
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7ee0173f907cac2f49d5f7e04750e0ea29b88d1a85ad21adbfa57217c1ab85fd731693e085b8265cdae78b18c1deb96776841ed66f98e90baaef4efce91a7ea
|
7
|
+
data.tar.gz: a7a1e68d305dcf024506262e63d1f08f12e9042280dadd80f711e6e25b2ec2edb685d6b04f103b464fd5bd5db7a242384d753c2d444b8efb615f6834da3bd53b
|
data/bin/dicebag
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
-
|
4
|
+
|
5
5
|
require_relative '../lib/dicebag'
|
6
6
|
|
7
7
|
# Define the Dicebag CLI app
|
@@ -18,14 +18,25 @@ class DiceBagCLI
|
|
18
18
|
|
19
19
|
def opts
|
20
20
|
@opts ||= OptionParser.new do |args|
|
21
|
+
args.banner = 'Usage: dicebag [-n | --notes] <dice string>'
|
22
|
+
|
21
23
|
args.on '-n', '--notes', 'Display any notes for the roll.'
|
24
|
+
|
25
|
+
args.on_head('-h', 'Displays this help.') do
|
26
|
+
puts args
|
27
|
+
|
28
|
+
exit
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
25
33
|
def perform
|
34
|
+
abort(opts.help) if ARGV.empty?
|
35
|
+
|
26
36
|
nonopts = opts.parse! into: params
|
27
37
|
|
28
|
-
|
38
|
+
dstr = nonopts.join(' ')
|
39
|
+
roll = DiceBag::Roll.new dstr
|
29
40
|
result = roll.roll
|
30
41
|
|
31
42
|
puts result
|
data/lib/dicebag/normalize.rb
CHANGED
@@ -101,13 +101,21 @@ module DiceBag
|
|
101
101
|
|
102
102
|
explode = hash[:options][:explode]
|
103
103
|
|
104
|
-
|
104
|
+
# If we did not come with a value, set it to dice sides, but no
|
105
|
+
# need to note this, as this is what no values means.
|
106
|
+
return __set_explode_to_sides(hash) if explode.negative?
|
105
107
|
|
106
|
-
|
108
|
+
# But we do want to note if the explode value was set to 1. >:|
|
109
|
+
__set_explode_to_sides if explode == 1
|
107
110
|
|
108
111
|
hash[:notes].push("Explode set to #{hash[:sides]}")
|
109
112
|
end
|
110
113
|
|
114
|
+
# :nodoc:
|
115
|
+
def __set_explode_to_sides(hash)
|
116
|
+
hash[:options][:explode] = hash[:sides]
|
117
|
+
end
|
118
|
+
|
111
119
|
# Prevent Reroll abuse.
|
112
120
|
def normalize_reroll(hash)
|
113
121
|
return unless hash[:options].key?(:reroll) &&
|
data/lib/dicebag/parser.rb
CHANGED
@@ -6,11 +6,11 @@ module DiceBag
|
|
6
6
|
# Base rules.
|
7
7
|
rule(:space?) { str(' ').repeat }
|
8
8
|
|
9
|
-
# Numbers are limited to
|
9
|
+
# Numbers are limited to 4 digit places.
|
10
10
|
#
|
11
11
|
# Why? To prevent abuse from people rolling: 999999999D999999999 and
|
12
12
|
# 'DOS'-ing the app.
|
13
|
-
rule(:number) { match('[0-9]').repeat(1,
|
13
|
+
rule(:number) { match('[0-9]').repeat(1, 4) }
|
14
14
|
rule(:number?) { number.maybe }
|
15
15
|
|
16
16
|
# Label rule
|
data/lib/dicebag/roll_part.rb
CHANGED
@@ -96,14 +96,14 @@ module DiceBag
|
|
96
96
|
def generate_results
|
97
97
|
@results = []
|
98
98
|
|
99
|
-
explode = @options
|
99
|
+
explode = @options[:explode]
|
100
100
|
|
101
101
|
count.times do
|
102
102
|
roll = roll_die
|
103
103
|
|
104
104
|
@results.push(roll)
|
105
105
|
|
106
|
-
handle_explode(roll)
|
106
|
+
handle_explode(roll) unless explode.nil?
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -34,9 +34,9 @@ module RollPartString
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def to_s_explode
|
37
|
-
return unless @options.key?(:explode)
|
37
|
+
return unless @options.key?(:explode) && @options[:explode].positive?
|
38
38
|
|
39
|
-
e =
|
39
|
+
e = format('e%s', @options[:explode])
|
40
40
|
|
41
41
|
@parts.push e
|
42
42
|
end
|
data/lib/dicebag/transform.rb
CHANGED
@@ -5,6 +5,8 @@ module DiceBag
|
|
5
5
|
# pass later.)
|
6
6
|
class Transform < Parslet::Transform
|
7
7
|
def self.hashify_options(options)
|
8
|
+
return options if options.is_a? Hash
|
9
|
+
|
8
10
|
opts = {}
|
9
11
|
|
10
12
|
options.each { |val| opts.update val } if options.respond_to?(:each)
|
@@ -40,9 +42,9 @@ module DiceBag
|
|
40
42
|
end
|
41
43
|
|
42
44
|
# Explode is special, in that if it is nil, then we set it to -1 to
|
43
|
-
# reflect that.
|
45
|
+
# reflect that, and it'll be updated in the normalization phase.
|
44
46
|
rule(explode: simple(:x)) do
|
45
|
-
{ explode: (x ? Integer(x) :
|
47
|
+
{ explode: (x ? Integer(x) : -1) }
|
46
48
|
end
|
47
49
|
|
48
50
|
# Match a label by itself.
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dicebag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Randy "syntruth" Carnahan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.3.26
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: 'Dice Bag: Ruby Dice Rolling Library'
|