mythal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +21 -0
- data/Rakefile +10 -0
- data/bin/console +13 -0
- data/bin/setup +8 -0
- data/exe/mythal +5 -0
- data/lib/mythal.rb +13 -0
- data/lib/mythal/roll.rb +65 -0
- data/lib/mythal/version.rb +3 -0
- data/mythal.gemspec +30 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6149d95e592338ab8239bc149dfba631056e4632
|
4
|
+
data.tar.gz: 5630aef755b4fb287b79e832abf98961cbdaf6d3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f4d6958ed30d9f69c6de1b4f79cb50edb62ee81c14eacba931db1e08e1476261c6f3c055986b5c949d137e8eb6c1ff606654e20f40e0187b8c9521699c98e49
|
7
|
+
data.tar.gz: f6c72fdf1c5258f78cf134b0eb94c4a333e4058acd2fc71a8a9befe1bb1fb56663cf738bfad3ac6cecc197f46d6cc215fa8e1b7216aff21cef57ac12ff152dee
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 George Groh
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Mythal
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'mythal'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mythal
|
18
|
+
|
19
|
+
## License
|
20
|
+
|
21
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mythal"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
11
|
+
|
12
|
+
# require "irb"
|
13
|
+
# IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/mythal
ADDED
data/lib/mythal.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "mythal"
|
2
|
+
require "thor"
|
3
|
+
require "procto"
|
4
|
+
require "mythal/roll"
|
5
|
+
|
6
|
+
module Mythal
|
7
|
+
class CLI < Thor
|
8
|
+
desc "roll", "roll some number of dice, plus modifiers e.g. 1d20, or 3d8 + 4"
|
9
|
+
def roll(*args)
|
10
|
+
puts Mythal::Roll.call(*args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/mythal/roll.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Mythal
|
2
|
+
class Roll
|
3
|
+
include Procto.call
|
4
|
+
|
5
|
+
DICE_VARIANTS = [4, 6, 8, 10, 12, 20]
|
6
|
+
NUMBER_OF_DICE = 1..100
|
7
|
+
|
8
|
+
def initialize(*dice_string)
|
9
|
+
@dice_string = dice_string.join
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
result
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :dice_string, :number_of_dice, :denomination, :bonus
|
19
|
+
|
20
|
+
def result
|
21
|
+
return "can't roll #{dice_string}" unless match_data
|
22
|
+
|
23
|
+
@number_of_dice = match_data[1].to_i
|
24
|
+
@denomination = match_data[2].to_i
|
25
|
+
@bonus = match_data[3]&.to_i || 0
|
26
|
+
|
27
|
+
return "can't roll #{dice_string}" unless valid_denomination?
|
28
|
+
return "can only roll #{min_dice} - #{max_dice} dice" unless valid_number_of_dice?
|
29
|
+
|
30
|
+
random_dice_roll + bonus
|
31
|
+
end
|
32
|
+
|
33
|
+
def random_dice_roll
|
34
|
+
number_of_dice.times.inject(0) do |memo, _val|
|
35
|
+
current_roll = rand(1..denomination)
|
36
|
+
puts "rolling d#{denomination}... #{current_roll}"
|
37
|
+
memo += current_roll
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def match_data
|
42
|
+
@match_data ||= (pattern.match(dice_string))
|
43
|
+
end
|
44
|
+
|
45
|
+
def pattern
|
46
|
+
@pattern ||= /^(-?\d+)d(\d+)\+?(\d+)?$/
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid_denomination?
|
50
|
+
DICE_VARIANTS.include?(denomination)
|
51
|
+
end
|
52
|
+
|
53
|
+
def valid_number_of_dice?
|
54
|
+
NUMBER_OF_DICE.include?(number_of_dice)
|
55
|
+
end
|
56
|
+
|
57
|
+
def min_dice
|
58
|
+
NUMBER_OF_DICE.min
|
59
|
+
end
|
60
|
+
|
61
|
+
def max_dice
|
62
|
+
NUMBER_OF_DICE.max
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/mythal.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mythal/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mythal"
|
8
|
+
spec.version = Mythal::VERSION
|
9
|
+
spec.authors = ["George Groh"]
|
10
|
+
spec.email = ["george.groh@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Roll D&D dice from the command line.}
|
13
|
+
spec.description = %q{Mythal is a command-line dice roller. Supports d4-d20. e.g. mythal roll 1d20 | mythal roll 3d6}
|
14
|
+
spec.homepage = "https://github.com/Inglorion-G/mythal"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
spec.add_development_dependency "pry", "~> 0.11.2"
|
28
|
+
spec.add_dependency "thor", "~> 0.20"
|
29
|
+
spec.add_dependency "procto"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mythal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- George Groh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-22 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.11.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.11.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.20'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.20'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: procto
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Mythal is a command-line dice roller. Supports d4-d20. e.g. mythal roll
|
98
|
+
1d20 | mythal roll 3d6
|
99
|
+
email:
|
100
|
+
- george.groh@gmail.com
|
101
|
+
executables:
|
102
|
+
- mythal
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- exe/mythal
|
115
|
+
- lib/mythal.rb
|
116
|
+
- lib/mythal/roll.rb
|
117
|
+
- lib/mythal/version.rb
|
118
|
+
- mythal.gemspec
|
119
|
+
homepage: https://github.com/Inglorion-G/mythal
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.6.8
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Roll D&D dice from the command line.
|
143
|
+
test_files: []
|