rpg_lib 1.0.0
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 +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +9 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +57 -0
- data/Rakefile +28 -0
- data/lib/rpg_lib.rb +22 -0
- data/lib/rpg_lib/api.rb +11 -0
- data/lib/rpg_lib/dice_roller.rb +82 -0
- data/lib/rpg_lib/roll_descriptor.rb +54 -0
- data/lib/rpg_lib/roll_set.rb +56 -0
- data/lib/rpg_lib/string.rb +29 -0
- data/lib/rpg_lib/version.rb +20 -0
- data/rpg_lib.gemspec +43 -0
- data/spec/rpg_lib/roll_set_spec.rb +114 -0
- data/spec/rpg_lib/string_spec.rb +72 -0
- data/spec/rpg_lib_spec.rb +24 -0
- data/spec/spec_helper.rb +21 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d34b6d848dfd8d8f76606d2ff2da3e4db758349f
|
4
|
+
data.tar.gz: 92897b0065a31f7c747b0806a9be0ec7a0d8b99d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5cc706792314e57fc3a7612194b215a4f8e9b6c02aef932c8150e26b0d836589830c28d2292ab9335877058df7da9ad7a49fd8d68576d805fa45577e6e058d14
|
7
|
+
data.tar.gz: 035d42799027fdadcafdb903d7c4ab8a7355cb05bb0d0ec49e54ca62e3271bd68bbc319aad6598f080c8a4331ec653484fd093cf9350e12dddd14445b698537b
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/coverage
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rpg_lib (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.3.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
docile (1.1.5)
|
12
|
+
json (2.0.3)
|
13
|
+
parser (2.4.0.0)
|
14
|
+
ast (~> 2.2)
|
15
|
+
powerpack (0.1.1)
|
16
|
+
rainbow (2.2.1)
|
17
|
+
rake (12.0.0)
|
18
|
+
rspec (3.5.0)
|
19
|
+
rspec-core (~> 3.5.0)
|
20
|
+
rspec-expectations (~> 3.5.0)
|
21
|
+
rspec-mocks (~> 3.5.0)
|
22
|
+
rspec-core (3.5.4)
|
23
|
+
rspec-support (~> 3.5.0)
|
24
|
+
rspec-expectations (3.5.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.5.0)
|
27
|
+
rspec-mocks (3.5.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.5.0)
|
30
|
+
rspec-support (3.5.0)
|
31
|
+
rubocop (0.47.1)
|
32
|
+
parser (>= 2.3.3.1, < 3.0)
|
33
|
+
powerpack (~> 0.1)
|
34
|
+
rainbow (>= 1.99.1, < 3.0)
|
35
|
+
ruby-progressbar (~> 1.7)
|
36
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
37
|
+
ruby-progressbar (1.8.1)
|
38
|
+
simplecov (0.14.0)
|
39
|
+
docile (~> 1.1.0)
|
40
|
+
json (>= 1.8, < 3)
|
41
|
+
simplecov-html (~> 0.10.0)
|
42
|
+
simplecov-html (0.10.0)
|
43
|
+
unicode-display_width (1.1.3)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
bundler (~> 1.14)
|
50
|
+
rake (~> 12.0)
|
51
|
+
rpg_lib!
|
52
|
+
rspec (~> 3.5)
|
53
|
+
rubocop (~> 0.47)
|
54
|
+
simplecov (~> 0.13)
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
1.14.6
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require 'bundler/gem_tasks'
|
19
|
+
require 'rake/clean'
|
20
|
+
require 'rspec/core/rake_task'
|
21
|
+
|
22
|
+
RSpec::Core::RakeTask.new(:spec)
|
23
|
+
|
24
|
+
task default: :spec
|
25
|
+
|
26
|
+
task :rubocop do
|
27
|
+
sh 'bundle exec rubocop'
|
28
|
+
end
|
data/lib/rpg_lib.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require 'rpg_lib/version'
|
19
|
+
require 'rpg_lib/roll_set'
|
20
|
+
require 'rpg_lib/roll_descriptor'
|
21
|
+
require 'rpg_lib/dice_roller'
|
22
|
+
require 'rpg_lib/string'
|
data/lib/rpg_lib/api.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require 'singleton'
|
19
|
+
|
20
|
+
module RpgLib
|
21
|
+
##
|
22
|
+
# DiceRoller
|
23
|
+
#
|
24
|
+
class DiceRoller
|
25
|
+
include Singleton
|
26
|
+
|
27
|
+
DICE_REGEXP = /(\d*)d(\d+)((dl)(\d*)|(dh)(\d*))?/
|
28
|
+
|
29
|
+
def random_value_in_range(range)
|
30
|
+
rand(range)
|
31
|
+
end
|
32
|
+
|
33
|
+
def roll_dice(roll_descriptor)
|
34
|
+
rolled_values = roll_all_dice_from_descriptor(roll_descriptor)
|
35
|
+
drop_lowest(rolled_values, roll_descriptor)
|
36
|
+
drop_highest(rolled_values, roll_descriptor)
|
37
|
+
total(rolled_values)
|
38
|
+
end
|
39
|
+
|
40
|
+
def roll(dice)
|
41
|
+
local_dice = dice.dup
|
42
|
+
loop do
|
43
|
+
m = local_dice.downcase.match(DICE_REGEXP)
|
44
|
+
break if m.nil?
|
45
|
+
rolled_value = roll_dice(RollDescriptor.new(m))
|
46
|
+
local_dice[m.begin(0)...m.end(0)] = rolled_value.to_s
|
47
|
+
end
|
48
|
+
eval(local_dice)
|
49
|
+
end
|
50
|
+
|
51
|
+
def roll_and_ignore(dice, ignored_values)
|
52
|
+
rolled_value = nil
|
53
|
+
loop do
|
54
|
+
rolled_value = roll(dice)
|
55
|
+
break unless ignored_values.include?(rolled_value)
|
56
|
+
end
|
57
|
+
rolled_value
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def roll_all_dice_from_descriptor(roll_descriptor)
|
63
|
+
rolled_values = []
|
64
|
+
1.upto roll_descriptor.count do
|
65
|
+
rolled_values << random_value_in_range(1..roll_descriptor.die)
|
66
|
+
end
|
67
|
+
rolled_values.sort
|
68
|
+
end
|
69
|
+
|
70
|
+
def drop_lowest(rolled_values, roll_descriptor)
|
71
|
+
rolled_values.slice!(0, roll_descriptor.drop_lowest)
|
72
|
+
end
|
73
|
+
|
74
|
+
def drop_highest(rolled_values, roll_descriptor)
|
75
|
+
rolled_values.slice!(rolled_values.size - roll_descriptor.drop_highest, roll_descriptor.drop_highest)
|
76
|
+
end
|
77
|
+
|
78
|
+
def total(rolled_values)
|
79
|
+
rolled_values.inject(:+)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
module RpgLib
|
19
|
+
##
|
20
|
+
# RollDescriptor
|
21
|
+
#
|
22
|
+
class RollDescriptor
|
23
|
+
attr_reader :die, :count, :drop_lowest, :drop_highest
|
24
|
+
|
25
|
+
def initialize(match)
|
26
|
+
initialize_die(match)
|
27
|
+
initialize_count(match)
|
28
|
+
initialize_dropped_dice(match)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def initialize_die(match)
|
34
|
+
@die = match[2].to_i
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize_count(match)
|
38
|
+
@count = 1
|
39
|
+
@count = match[1].to_i unless match[1].empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize_dropped_dice(match)
|
43
|
+
@drop_lowest = 0
|
44
|
+
@drop_highest = 0
|
45
|
+
if match[4] == 'dl'
|
46
|
+
@drop_lowest = 1
|
47
|
+
@drop_lowest = match[5].to_i unless match[5].empty?
|
48
|
+
elsif match[6] == 'dh'
|
49
|
+
@drop_highest = 1
|
50
|
+
@drop_highest = match[7].to_i unless match[7].empty?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require 'set'
|
19
|
+
|
20
|
+
module RpgLib
|
21
|
+
##
|
22
|
+
# RollSet
|
23
|
+
#
|
24
|
+
class RollSet
|
25
|
+
attr_reader :rolls
|
26
|
+
|
27
|
+
def initialize(*args)
|
28
|
+
@rolls = Set.new
|
29
|
+
args.each { |a| add(a) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def empty?
|
33
|
+
@rolls.empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
def include?(roll)
|
37
|
+
@rolls.include?(roll)
|
38
|
+
end
|
39
|
+
|
40
|
+
def add(r)
|
41
|
+
if r.is_a?(Integer)
|
42
|
+
@rolls.add(r)
|
43
|
+
elsif r.is_a?(Range)
|
44
|
+
r.to_a.map { |e| @rolls.add(e) }
|
45
|
+
elsif r.is_a?(RollSet)
|
46
|
+
@rolls.merge(r.rolls)
|
47
|
+
else
|
48
|
+
raise Exception, "Invalid type (#{r.class}) added to roll set"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
@rolls.to_a.join(', ')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
##
|
19
|
+
# String Patch
|
20
|
+
#
|
21
|
+
class String
|
22
|
+
def roll
|
23
|
+
RpgLib::DiceRoller.instance.roll(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def roll_and_ignore(*args)
|
27
|
+
RpgLib::DiceRoller.instance.roll_and_ignore(self, RpgLib::RollSet.new(*args))
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
module RpgLib
|
19
|
+
VERSION = '1.0.0'.freeze
|
20
|
+
end
|
data/rpg_lib.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
# coding: utf-8
|
19
|
+
lib = File.expand_path('../lib', __FILE__)
|
20
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
21
|
+
|
22
|
+
require 'rpg_lib/version'
|
23
|
+
|
24
|
+
Gem::Specification.new do |spec|
|
25
|
+
spec.name = 'rpg_lib'
|
26
|
+
spec.version = RpgLib::VERSION
|
27
|
+
spec.date = '2015-05-05'
|
28
|
+
spec.summary = 'RPG Library'
|
29
|
+
spec.description = 'Library of tools for automating role-playing game tasks.'
|
30
|
+
spec.authors = ['Jamie Hale']
|
31
|
+
spec.email = ['jamie@smallarmyofnerds.com']
|
32
|
+
spec.homepage = 'https://github.com/jamiehale/rpglib'
|
33
|
+
spec.license = 'GPL-3.0'
|
34
|
+
spec.platform = Gem::Platform::RUBY
|
35
|
+
spec.files = `git ls-files -z`.split("\x0")
|
36
|
+
spec.require_paths = ['lib']
|
37
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
38
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
39
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
40
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
41
|
+
spec.add_development_dependency 'simplecov', '~> 0.13'
|
42
|
+
spec.add_development_dependency 'rubocop', '~> 0.47'
|
43
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
module RpgLib
|
21
|
+
describe RollSet do
|
22
|
+
it 'can be created' do
|
23
|
+
expect { RollSet.new }.not_to raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'when empty' do
|
27
|
+
let(:roll_set) { RollSet.new }
|
28
|
+
|
29
|
+
it 'has no rolls' do
|
30
|
+
expect(roll_set.rolls).to be_empty
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'is empty' do
|
34
|
+
expect(roll_set).to be_empty
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has an empty string rep' do
|
38
|
+
expect(roll_set.to_s).to be_empty
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'adding integer' do
|
42
|
+
before(:each) do
|
43
|
+
roll_set.add(4)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'is no longer empty' do
|
47
|
+
expect(roll_set).not_to be_empty
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'has the roll' do
|
51
|
+
expect(roll_set).to include(4)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'has a simple string rep' do
|
55
|
+
expect(roll_set.to_s).to eq('4')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'adding range' do
|
60
|
+
before(:each) do
|
61
|
+
roll_set.add(2..5)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'is no longer empty' do
|
65
|
+
expect(roll_set).not_to be_empty
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'includes all rolls' do
|
69
|
+
expect(roll_set).to include(2, 3, 4, 5)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'has a string rep' do
|
73
|
+
expect(roll_set.to_s).to eq('2, 3, 4, 5')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'adding roll set' do
|
78
|
+
before(:each) do
|
79
|
+
roll_set.add(RollSet.new(3, 5, 7))
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'is no longer empty' do
|
83
|
+
expect(roll_set).not_to be_empty
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'includes all rolls' do
|
87
|
+
expect(roll_set).to include(3, 5, 7)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'has a string rep' do
|
91
|
+
expect(roll_set.to_s).to eq('3, 5, 7')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'adding multiple types' do
|
96
|
+
before(:each) do
|
97
|
+
roll_set.add(1)
|
98
|
+
roll_set.add(2..5)
|
99
|
+
roll_set.add(RollSet.new(6..7))
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'includes all rolls' do
|
103
|
+
expect(roll_set).to include(1, 2, 3, 4, 5, 6, 7)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'adding invalid type' do
|
108
|
+
it 'throws when adding anything other than integer, range, or roll set' do
|
109
|
+
expect { roll_set.add('fail') }.to raise_error(Exception)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
module RpgLib
|
21
|
+
describe 'String patch' do
|
22
|
+
describe 'roll' do
|
23
|
+
it 'returns Integer' do
|
24
|
+
expect('3d6'.roll).to be_instance_of(Integer)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'responds in the specified range' do
|
28
|
+
20.times do
|
29
|
+
roll = '3d6'.roll
|
30
|
+
expect(roll < 3).to be false
|
31
|
+
expect(roll > 18).to be false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'roll_and_ignore' do
|
37
|
+
it 'returns Integer' do
|
38
|
+
expect('3d6'.roll_and_ignore(5)).to be_instance_of(Integer)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'response in the specified range' do
|
42
|
+
20.times do
|
43
|
+
roll = '3d6'.roll_and_ignore(5)
|
44
|
+
expect(roll < 3).to be false
|
45
|
+
expect(roll > 18).to be false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'ignores a passed number' do
|
50
|
+
20.times do
|
51
|
+
roll = '3d6'.roll_and_ignore(5)
|
52
|
+
expect(roll).not_to eq(5)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'ignores a passed range' do
|
57
|
+
20.times do
|
58
|
+
roll = '3d6'.roll_and_ignore(6..10)
|
59
|
+
expect(6..10).not_to include(roll)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'ignores a passed roll set' do
|
64
|
+
evens = RollSet.new(4, 6, 8, 10, 12, 14, 16, 18)
|
65
|
+
20.times do
|
66
|
+
roll = '3d6'.roll_and_ignore(evens)
|
67
|
+
expect(roll).to be_odd
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
describe RpgLib do
|
21
|
+
it 'has a version number' do
|
22
|
+
expect(RpgLib::VERSION).not_to be nil
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Copyright 2017 Jamie Hale
|
2
|
+
#
|
3
|
+
# This file is part of the RpgLib gem.
|
4
|
+
#
|
5
|
+
# RpgLib is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# RpgLib is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with RpgLib. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
19
|
+
require 'simplecov'
|
20
|
+
SimpleCov.start
|
21
|
+
require 'rpg_lib'
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpg_lib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamie Hale
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.47'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.47'
|
83
|
+
description: Library of tools for automating role-playing game tasks.
|
84
|
+
email:
|
85
|
+
- jamie@smallarmyofnerds.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- Rakefile
|
95
|
+
- lib/rpg_lib.rb
|
96
|
+
- lib/rpg_lib/api.rb
|
97
|
+
- lib/rpg_lib/dice_roller.rb
|
98
|
+
- lib/rpg_lib/roll_descriptor.rb
|
99
|
+
- lib/rpg_lib/roll_set.rb
|
100
|
+
- lib/rpg_lib/string.rb
|
101
|
+
- lib/rpg_lib/version.rb
|
102
|
+
- rpg_lib.gemspec
|
103
|
+
- spec/rpg_lib/roll_set_spec.rb
|
104
|
+
- spec/rpg_lib/string_spec.rb
|
105
|
+
- spec/rpg_lib_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
homepage: https://github.com/jamiehale/rpglib
|
108
|
+
licenses:
|
109
|
+
- GPL-3.0
|
110
|
+
metadata:
|
111
|
+
allowed_push_host: https://rubygems.org
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.6.8
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: RPG Library
|
132
|
+
test_files: []
|