gm-notepad 0.0.16 → 0.0.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b186d6ae4ff1019ca4e0a1c9beab65a156466928024da4b736c021bc70cfa3e9
4
- data.tar.gz: 114b921bd96b0e2c4c2b489cbe9412b1e0bf61515fce5b378f61c38ec87ff79f
3
+ metadata.gz: 4175bf606855b4c2be432ac4520727705e708f16583cbf9a616d5246e46aa1f2
4
+ data.tar.gz: 1877cf77a1aef0e1e7697d673d1a021fe907b964ab21c9adbb38c1ecda784428
5
5
  SHA512:
6
- metadata.gz: 587d8929143a4680253c0c0f45ea4ae482df3956c97b85dd5ff6fbb0113af4bb46961c3511bb1eb59b4e8bb4f916958432349d96dbdc93acccda8cafd428353f
7
- data.tar.gz: b5cbba4aaf0778ef19f99dbddec1335d0febafd02075539650a9f922a1ad027fa77709386c7f9e18df2b59fcd9bbe51f95fb70badfab3bb70eec2ddf71523ffa
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
- - [ ] For `{critical[{2d6+1}]}`, how to handle out of bounds
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
- - [ ] Add auto table expansion for "{}"
285
- - [ ] Add auto table expansion for "+"
284
+ - [X] Add auto table expansion for "{}"
285
+ - [X] Add auto table expansion for "+"
286
286
  - [ ] Add auto index expansion for "["
287
- - [ ] Determine feasibility of adding dice to the `{}` expansion syntax (instead of the `[]` syntax)
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 = 97
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
@@ -5,7 +5,7 @@
5
5
  ?
6
6
 
7
7
  # Should roll the dice
8
- [2d6] goblins attack
8
+ {2d6} goblins attack
9
9
 
10
10
  # Should render to interactive the given tables
11
11
  +
@@ -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
- raise MissingTableEntryError.new(table_name: table_name, index: index.to_s)
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
- class TableEntry
8
- extend Dry::Initializer
9
- option :line, proc(&:to_s)
10
- option :table
11
- option :column_delimiter, default: -> { Container.resolve(:config).column_delimiter }
12
-
13
- def initialize(*args)
14
- super
15
- row = line.split(column_delimiter)
16
- self.index = row.shift
17
- self.cells = row
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
- include Comparable
21
- def <=>(other)
22
- to_str <=> String(other)
23
- end
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
- def lookup(cell:)
26
- index = table.column_index_for(cell: cell)
27
- cells[index] || cells[0]
28
- end
32
+ include Comparable
33
+ def <=>(other)
34
+ to_str <=> String(other)
35
+ end
29
36
 
30
- NUMBER_RANGE_REGEXP = %r{(?<left>\d+) *- *(?<right>\d+)}
31
- def lookup_range
32
- if match = NUMBER_RANGE_REGEXP.match(index)
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
- attr_reader :index, :cells
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
- def entry
42
- cells.join("\t")
43
- end
44
- alias entry_column entry
51
+ attr_reader :index, :cells
45
52
 
46
- def to_s
47
- "[#{index}]\t#{entry}"
48
- end
49
- alias to_str entry
53
+ def entry
54
+ cells.join("\t")
55
+ end
56
+ alias entry_column entry
50
57
 
51
- private
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
- def index=(input)
54
- @index = input.strip.downcase.freeze
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
- def cells=(input)
58
- @cells = Array(input).map { |i| i.strip.freeze }.freeze
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
@@ -1,5 +1,5 @@
1
1
  module Gm
2
2
  module Notepad
3
- VERSION = "0.0.16"
3
+ VERSION = "0.0.17"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gm-notepad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen