dicebag 3.3.0 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b36691cc7b34c8637154bac79f610b1867d55902b904e83b390b12ae1e6ebf37
4
- data.tar.gz: d3fb57f5f563a1e599beb75831953ff3e8bc6dd2e60fcc82aee66a609ac96b1a
3
+ metadata.gz: 2c9b311916035f1eaf3e31fd09c0eba523bc426875ca25ea0929d131215df709
4
+ data.tar.gz: 3c7c973630fdc29c654f3b90009d32652da06763a2e6a44fc5d2edb643215b96
5
5
  SHA512:
6
- metadata.gz: d0367e80fdfc838a465a5b431c766a3418dcb35ae99f8cce9a6ee9f040e6dd4b859b1c561a36f6bfbed16e88a4e9e817e9f9c077263de8721e72498ab9e6e63d
7
- data.tar.gz: d1cf650ccb9d0a75fcfb9d278198b949c17291ebf488878f3c7df3a3accb63ac8c9e9ed8c00b1ffb6222369fd6ed9c0ad1bad8a5c5c8b471cefd59e7cffa63d7
6
+ metadata.gz: 735fae23c00f6c883f4370bd8ca2a9451b6747264664b820f6f2b36ea062c8f3167197be28e17c83978d82a887c2d71cf5236af5519865913f23a0773145d087
7
+ data.tar.gz: 8c9c8fbc7ad416cf954da26a9118e040863a8cfb8b2ca0e71b9e8b0248d282ef0ff17bb66646433e93c6d55d8c359fc95962ceaba0205f8889500319271cd479
data/bin/dicebag CHANGED
@@ -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
- roll = DiceBag::Roll.new nonopts.first
38
+ dstr = nonopts.join(' ')
39
+ roll = DiceBag::Roll.new dstr
29
40
  result = roll.roll
30
41
 
31
42
  puts result
@@ -101,13 +101,21 @@ module DiceBag
101
101
 
102
102
  explode = hash[:options][:explode]
103
103
 
104
- return if explode.nil? || explode >= 2
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
- hash[:options][:explode] = nil
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) &&
@@ -96,14 +96,14 @@ module DiceBag
96
96
  def generate_results
97
97
  @results = []
98
98
 
99
- explode = @options.key?(:explode)
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) if explode
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 = @options[:explode].nil? ? 'e' : format('e%s', @options[:explode])
39
+ e = format('e%s', @options[:explode])
40
40
 
41
41
  @parts.push e
42
42
  end
@@ -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) : nil) }
47
+ { explode: (x ? Integer(x) : -1) }
46
48
  end
47
49
 
48
50
  # Match a label by itself.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dicebag
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SynTruth