crapshoot 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,10 +37,12 @@ Generally, whitespace is allowed around arithmetic operations, but not inside a
37
37
  == Describing a Roll
38
38
 
39
39
  The return value from +Crapshoot.roll+ is a Crapshoot::Result object,
40
- which is an Integer with a description field:
40
+ which is an Integer with a +description+ field and a +detailed_description+
41
+ field:
41
42
 
42
43
  r = Crapshoot.roll '4d4^ + 6d6 - 10' # => 22
43
44
  r.description # => "(2+2+2+3-3)+(1+3+5+5+6+6)-10"
45
+ r.detailed_description # => [["4d4^", "2+2+2+3-3"], ["+", "+"], ["6d6", "1+3+5+5+6+6"], ["-", "-"], ["10", "10"]]
44
46
  r + 5 # => 27
45
47
 
46
48
  == Developing with Ragel
@@ -7,7 +7,6 @@ Gem::Specification.new do |s|
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["Bryce Kerley"]
10
- s.date = %q{2011-09-03}
11
10
  s.description = "Crapshoot is a dice-rolling gem for most of your pen-and-paper gaming needs; roll 4d6v to find out how much time it will save."
12
11
  s.email = "bkerley@brycekerley.net"
13
12
  s.extra_rdoc_files = [
@@ -10,5 +10,8 @@ module Crapshoot
10
10
 
11
11
  # The derivation of the result, as a String.
12
12
  attr_accessor :description
13
+
14
+ # The derivation of the result, broken down by tokens, as an Array.
15
+ attr_accessor :detailed_description
13
16
  end
14
17
  end
@@ -23,6 +23,7 @@ module Crapshoot
23
23
  l = stack.pop
24
24
  @result = Result.new l.send(@operation.to_sym, r)
25
25
  @result.description = "#{l.description}#{@operation}#{r.description}"
26
+ @result.detailed_description = l.detailed_description + [[@operation, @operation]] + r.detailed_description
26
27
  return @result
27
28
  end
28
29
 
@@ -4,6 +4,7 @@ module Crapshoot
4
4
  def initialize(number)
5
5
  @value = Result.new number.to_i
6
6
  @value.description = @value.to_s
7
+ @value.detailed_description = [[@value.to_s, @value.to_s]]
7
8
  end
8
9
 
9
10
  def eval(stack)
@@ -24,6 +24,7 @@ module Crapshoot
24
24
  end
25
25
  @result = Result.new numeric_result
26
26
  @result.description = "(#{roll_description})"
27
+ @result.detailed_description = [["#{@count}d#{@sides}#{@drop}", roll_description]]
27
28
 
28
29
  return @result
29
30
  end
@@ -1,3 +1,3 @@
1
1
  module Crapshoot
2
- VERSION = '0.4.2'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -15,12 +15,23 @@ class TestCrapshoot < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  def self.should_describe(from, matcher)
18
- should "evaluate #{from.inspect} into something resembling #{matcher.inspect}" do
18
+ should "describe #{from.inspect} into something resembling #{matcher.inspect}" do
19
19
  result = Crapshoot.roll from
20
20
  assert_match matcher, result.description
21
21
  end
22
22
  end
23
23
 
24
+ def self.should_array_describe(from, matcher)
25
+ should "describe #{from.inspect} into a big array resembling #{matcher.inspect}" do
26
+ result = Crapshoot.roll from
27
+ result.detailed_description.zip(matcher) do |result_piece, matcher_piece|
28
+ result_piece.zip(matcher_piece) do |r, m|
29
+ assert_match m, r
30
+ end
31
+ end
32
+ end
33
+ end
34
+
24
35
  context 'The Crapshoot module' do
25
36
  should_roll '4d6', '>='=>4, '<='=>24
26
37
  should_roll '4d6 + 200', '>='=>204, '<='=>224
@@ -40,5 +51,16 @@ class TestCrapshoot < Test::Unit::TestCase
40
51
  should_describe '2d6 + 5', /\(\d\+\d\)\+5/
41
52
  should_describe '2d6 + 5 + 4d2v', /\(\d\+\d\)\+5\+\(\d\+\d\+\d\+\d\-\d\)/
42
53
  should_describe '2d6 + 5 + 4d2^', /\(\d\+\d\)\+5\+\(\d\+\d\+\d\+\d\-\d\)/
54
+
55
+ should_array_describe '1 + 2', [['1', '1'], ['+', '+'], ['2', '2']]
56
+ should_array_describe '10 - 5', [['10', '10'], ['-', '-'], ['5', '5']]
57
+ should_array_describe '2d6', [['2d6', /\d\+\d/]]
58
+ should_array_describe '2d6 + 5', [['2d6', /\d\+\d/], ['+', '+'], ['5', '5']]
59
+ should_array_describe '2d6 + 5 + 4d2v', [['2d6', /\d\+\d/],
60
+ ['+', '+'],
61
+ ['5', '5'],
62
+ ['+', '+'],
63
+ ['4d2v', /\d\+\d\+\d\+\d\-\d/]]
64
+
43
65
  end
44
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crapshoot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-03 00:00:00.000000000Z
12
+ date: 2011-12-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70268233908940 !ruby/object:Gem::Requirement
16
+ requirement: &70102833186080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70268233908940
24
+ version_requirements: *70102833186080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: guard-test
27
- requirement: &70268233908200 !ruby/object:Gem::Requirement
27
+ requirement: &70102833185500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.1.4
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70268233908200
35
+ version_requirements: *70102833185500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shoulda
38
- requirement: &70268233906760 !ruby/object:Gem::Requirement
38
+ requirement: &70102833184980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.11.3
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70268233906760
46
+ version_requirements: *70102833184980
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &70268233905320 !ruby/object:Gem::Requirement
49
+ requirement: &70102833184220 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 1.0.7
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70268233905320
57
+ version_requirements: *70102833184220
58
58
  description: Crapshoot is a dice-rolling gem for most of your pen-and-paper gaming
59
59
  needs; roll 4d6v to find out how much time it will save.
60
60
  email: bkerley@brycekerley.net