gm-notepad 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/Rakefile +1 -1
- data/examples/basic_example_file +1 -1
- data/lib/gm/notepad/table.rb +17 -1
- data/lib/gm/notepad/table_entry.rb +77 -40
- data/lib/gm/notepad/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4175bf606855b4c2be432ac4520727705e708f16583cbf9a616d5246e46aa1f2
|
4
|
+
data.tar.gz: 1877cf77a1aef0e1e7697d673d1a021fe907b964ab21c9adbb38c1ecda784428
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6b1d4a852e32922d6c18529584c9eb06645f440f7286b363b87767cb5094a6ae18dbf82f53c227bc2485d739a14b7b540482e0422ba81785db8e8337a92b763
|
7
|
+
data.tar.gz: 33b44cb7f7888c038152cc738ab861734b73509db733c2c5ee451270ad0936f883246735300a6b02ff9f760c119be38bb8209a0d99ca4b7575c25da5229dcb3b
|
data/README.md
CHANGED
@@ -248,7 +248,7 @@ You can then immediately access the `junk` table, by typing the following: `+jun
|
|
248
248
|
- [X] Handle `{critical[5]}`
|
249
249
|
- [X] Allow `{critical[{2d6+1}]}` to roll the dice then lookup the value in the critical table
|
250
250
|
- [X] Handle `{critical[{2d6}]} for {2d6} damage`
|
251
|
-
- [
|
251
|
+
- [X] For `{critical[{2d6+1}]}`, how to handle out of bounds
|
252
252
|
- [X] Skip table lines that begin with `#`
|
253
253
|
- [X] Skip processing input lines that begin with `#`
|
254
254
|
- [X] Allow configuration to specify table delimiter
|
@@ -281,10 +281,10 @@ You can then immediately access the `junk` table, by typing the following: `+jun
|
|
281
281
|
- [ ] Allow configuration to specify colors
|
282
282
|
- [ ] Aspiration: Enable `\{\{monster}[ac]}` to pick a random monster and then fetch that monster's AC
|
283
283
|
- [ ] Allow option to add a table to memory (instead of writing the table)
|
284
|
-
- [
|
285
|
-
- [
|
284
|
+
- [X] Add auto table expansion for "{}"
|
285
|
+
- [X] Add auto table expansion for "+"
|
286
286
|
- [ ] Add auto index expansion for "["
|
287
|
-
- [
|
287
|
+
- [X] Determine feasibility of adding dice to the `{}` expansion syntax (instead of the `[]` syntax)
|
288
288
|
- [ ] Add force write results to `output`
|
289
289
|
- [ ] Add option to dump all tables to the given directory
|
290
290
|
- [ ] Add config that expands dice results while including the requested roll
|
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ namespace :commitment do
|
|
17
17
|
lastrun_filename = File.expand_path('../coverage/.last_run.json', __FILE__)
|
18
18
|
if File.exist?(lastrun_filename)
|
19
19
|
coverage_percentage = JSON.parse(File.read(lastrun_filename)).fetch('result').fetch('covered_percent').to_i
|
20
|
-
EXPECTED_COVERAGE_GOAL =
|
20
|
+
EXPECTED_COVERAGE_GOAL = 98
|
21
21
|
if coverage_percentage < EXPECTED_COVERAGE_GOAL
|
22
22
|
abort("ERROR: Code Coverage Goal Not Met:\n\t#{coverage_percentage}%\tExpected\n\t#{EXPECTED_COVERAGE_GOAL}%\tActual")
|
23
23
|
else
|
data/examples/basic_example_file
CHANGED
data/lib/gm/notepad/table.rb
CHANGED
@@ -16,6 +16,8 @@ module Gm
|
|
16
16
|
def initialize(*args)
|
17
17
|
super
|
18
18
|
@table = {}
|
19
|
+
@or_less = []
|
20
|
+
@or_more = []
|
19
21
|
set_null_table_column_set!
|
20
22
|
process(lines: lines)
|
21
23
|
end
|
@@ -63,13 +65,27 @@ module Gm
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
68
|
+
def set_or_less_entry(table_entry)
|
69
|
+
@or_less = table_entry
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_or_more_entry(table_entry)
|
73
|
+
@or_more = table_entry
|
74
|
+
end
|
75
|
+
|
66
76
|
private
|
67
77
|
|
68
78
|
def lookup_entry_by(index:)
|
69
79
|
begin
|
70
80
|
@table.fetch(index.to_s)
|
71
81
|
rescue KeyError
|
72
|
-
|
82
|
+
if @or_less.include?(index.to_s)
|
83
|
+
@or_less
|
84
|
+
elsif @or_more.include?(index.to_s)
|
85
|
+
@or_more
|
86
|
+
else
|
87
|
+
raise MissingTableEntryError.new(table_name: table_name, index: index.to_s)
|
88
|
+
end
|
73
89
|
end
|
74
90
|
end
|
75
91
|
|
@@ -4,58 +4,95 @@ require 'gm/notepad/container'
|
|
4
4
|
module Gm
|
5
5
|
module Notepad
|
6
6
|
TABLE_ENTRY_RANGE_MARKER = "-".freeze
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
module TableEntry
|
8
|
+
OR_LESS_REGEXP = %r{\A(?<floor>\d+) or less}i.freeze
|
9
|
+
OR_MORE_REGEXP = %r{\A(?<ceiling>\d+) or more}i.freeze
|
10
|
+
def self.new(line:, table:, **kwargs)
|
11
|
+
if match = line.match(OR_LESS_REGEXP)
|
12
|
+
OrLess.new(line: line, table: table, floor: match[:floor], **kwargs)
|
13
|
+
elsif match = line.match(OR_MORE_REGEXP)
|
14
|
+
OrMore.new(line: line, table: table, ceiling: match[:ceiling], **kwargs)
|
15
|
+
else
|
16
|
+
Base.new(line: line, table: table, **kwargs)
|
17
|
+
end
|
18
18
|
end
|
19
|
+
class Base
|
20
|
+
extend Dry::Initializer
|
21
|
+
option :line, proc(&:to_s)
|
22
|
+
option :table
|
23
|
+
option :column_delimiter, default: -> { Container.resolve(:config).column_delimiter }
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
def initialize(*args)
|
26
|
+
super
|
27
|
+
row = line.split(column_delimiter)
|
28
|
+
self.index = row.shift
|
29
|
+
self.cells = row
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
32
|
+
include Comparable
|
33
|
+
def <=>(other)
|
34
|
+
to_str <=> String(other)
|
35
|
+
end
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
(match[:left].to_i..match[:right].to_i).map(&:to_s)
|
34
|
-
else
|
35
|
-
[index]
|
37
|
+
def lookup(cell:)
|
38
|
+
index = table.column_index_for(cell: cell)
|
39
|
+
cells[index] || cells[0]
|
36
40
|
end
|
37
|
-
end
|
38
41
|
|
39
|
-
|
42
|
+
NUMBER_RANGE_REGEXP = %r{(?<left>\d+) *- *(?<right>\d+)}
|
43
|
+
def lookup_range
|
44
|
+
if match = NUMBER_RANGE_REGEXP.match(index)
|
45
|
+
(match[:left].to_i..match[:right].to_i).map(&:to_s)
|
46
|
+
else
|
47
|
+
[index]
|
48
|
+
end
|
49
|
+
end
|
40
50
|
|
41
|
-
|
42
|
-
cells.join("\t")
|
43
|
-
end
|
44
|
-
alias entry_column entry
|
51
|
+
attr_reader :index, :cells
|
45
52
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
53
|
+
def entry
|
54
|
+
cells.join("\t")
|
55
|
+
end
|
56
|
+
alias entry_column entry
|
50
57
|
|
51
|
-
|
58
|
+
def to_s
|
59
|
+
"[#{index}]\t#{entry}"
|
60
|
+
end
|
61
|
+
alias to_str entry
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def index=(input)
|
66
|
+
@index = input.strip.downcase.freeze
|
67
|
+
end
|
52
68
|
|
53
|
-
|
54
|
-
|
69
|
+
def cells=(input)
|
70
|
+
@cells = Array(input).map { |i| i.strip.freeze }.freeze
|
71
|
+
end
|
55
72
|
end
|
73
|
+
class OrLess < Base
|
74
|
+
def initialize(floor:, **kwargs)
|
75
|
+
super
|
76
|
+
@floor = floor
|
77
|
+
table.set_or_less_entry(self)
|
78
|
+
end
|
79
|
+
attr_reader :floor
|
56
80
|
|
57
|
-
|
58
|
-
|
81
|
+
def include?(index)
|
82
|
+
floor.to_i >= index.to_i
|
83
|
+
end
|
84
|
+
end
|
85
|
+
class OrMore < Base
|
86
|
+
def initialize(ceiling:, **kwargs)
|
87
|
+
super
|
88
|
+
@ceiling = ceiling
|
89
|
+
table.set_or_more_entry(self)
|
90
|
+
end
|
91
|
+
attr_reader :ceiling
|
92
|
+
|
93
|
+
def include?(index)
|
94
|
+
ceiling.to_i <= index.to_i
|
95
|
+
end
|
59
96
|
end
|
60
97
|
end
|
61
98
|
end
|
data/lib/gm/notepad/version.rb
CHANGED