gm-notepad 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -3
- data/Rakefile +1 -1
- data/exe/gm-notepad +9 -5
- data/lib/gm/notepad/app.rb +3 -0
- data/lib/gm/notepad/config.rb +1 -1
- data/lib/gm/notepad/input_handlers/write_to_table_handler.rb +14 -27
- data/lib/gm/notepad/parameters/table_lookup.rb +6 -13
- data/lib/gm/notepad/table.rb +1 -8
- data/lib/gm/notepad/table_column_set.rb +3 -1
- data/lib/gm/notepad/table_entry.rb +7 -1
- 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: '0784714674a998ddc3d5fc89ca12a9bbff1837a18472236c66588b147fc62683'
|
4
|
+
data.tar.gz: cd5e95e5b42684c6d005d696e194c35bbe2ee7c130382e5b1b4ab75b12c09673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34053cf8caa8baf0a30cc5bef686f55e84ae464e296072fc1e3074af259dc05001f433937b7df42627b56076a807ea4bce8f5ba55b1fcde60e00194bcb0f4ed4
|
7
|
+
data.tar.gz: 0d16b0d3f31df32c84ec8f298634d2bf98cdb2806d2cfb0b47e32a33bd9103aacdc199f5594bc964ae6ef610a9298db352747a8f348bdd878826026e0a9aa904
|
data/README.md
CHANGED
@@ -10,6 +10,10 @@ Next, you'll want to install the `gm-notepad` gem.
|
|
10
10
|
|
11
11
|
`$ gem install gm-notepad`
|
12
12
|
|
13
|
+
## Datasets
|
14
|
+
|
15
|
+
* `[gm-notepad-swn-free](//github.com/jeremyf/gm-notepad-swn-free)` a subset of tables available in [Stars without Number: Revised Edition](https://www.drivethrurpg.com/product/226996/Stars-Without-Number-Revised-Edition?affiliate_id=318171)
|
16
|
+
|
13
17
|
## Background
|
14
18
|
|
15
19
|
On a commute home from work, while listening to [Judd Karlman's "Daydreaming about Dragons" podcast](https://anchor.fm/daydreaming-about-dragons/)
|
@@ -64,7 +68,7 @@ Options:
|
|
64
68
|
-p, --path=PATH Path(s) for {table_name}.<config.table_extension> files (Default: ["."])
|
65
69
|
-f, --filesystem_directory=DIR Path to dump tables (Default: ".")
|
66
70
|
-x, --table_extension=EXT Extension to use for selecting tables (Default: ".txt")
|
67
|
-
--time_to_live=TTL Per line of input, how many times to allow text expansion (Default:
|
71
|
+
--time_to_live=TTL Per line of input, how many times to allow text expansion (Default: 100)
|
68
72
|
-d, --delimiter=DELIM Default column delimiter for tables (Default: "|")
|
69
73
|
|
70
74
|
Output options:
|
@@ -98,7 +102,7 @@ Which writes the following to the `interactive` buffer (eg. `$stderr`)::
|
|
98
102
|
# config[:report_config] = true
|
99
103
|
# config[:skip_readlines] = false
|
100
104
|
# config[:table_extension] = ".txt"
|
101
|
-
# config[:time_to_live] =
|
105
|
+
# config[:time_to_live] = 100
|
102
106
|
# config[:with_timestamp] = false
|
103
107
|
```
|
104
108
|
|
@@ -270,10 +274,11 @@ You can then immediately access the `junk` table, by typing the following: `+jun
|
|
270
274
|
- [X] Gracefully handle cell lookup when named cell for entry is not found
|
271
275
|
- [X] Support `\{\{table}-name}` You should be able to do `\{\{culture}-name}` and first evaluate to `{arabic-name}` and then get a value from the `arabic-name` table
|
272
276
|
- [X] Ensure index names are lower-case
|
273
|
-
- [
|
277
|
+
- [X] Hit 100% spec coverage
|
274
278
|
- [X] Create a "To Render Object"; When you parse the input, you push relevant lines to that "To Render Object". When you look at a table, you want to know what the column names are.
|
275
279
|
- [X] Remove "defer" printing concept
|
276
280
|
- [X] Add ability to shell out; I would love to leverage the [swnt](https://github.com/nboughton/swnt) command line tool
|
281
|
+
- [ ] Refine row/column grep behavior, as it is pre-dates the idea of a table having columns
|
277
282
|
|
278
283
|
### Stretch TODO
|
279
284
|
|
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 = 100
|
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/exe/gm-notepad
CHANGED
@@ -39,12 +39,12 @@ OptionParser.new do |options|
|
|
39
39
|
config[:table_extension] = table_extension
|
40
40
|
end
|
41
41
|
|
42
|
-
options.on("-
|
42
|
+
options.on("-vTTL", "--time_to_live=TTL", Integer, "Per line of input, how many times to allow text expansion (Default: #{defaults.time_to_live.inspect})") do |time_to_live|
|
43
43
|
config[:time_to_live] = time_to_live
|
44
44
|
end
|
45
45
|
|
46
46
|
options.on("-dDELIM", "--delimiter=DELIM", String, "Default column delimiter for tables (Default: #{defaults.column_delimiter.inspect})") do |column_delimiter|
|
47
|
-
map = { "t" => "\t" }
|
47
|
+
map = { "t" => "\t", '\t' => "\t" }
|
48
48
|
config[:column_delimiter] = map.fetch(column_delimiter) { column_delimiter }
|
49
49
|
end
|
50
50
|
|
@@ -57,11 +57,15 @@ OptionParser.new do |options|
|
|
57
57
|
options.separator("")
|
58
58
|
options.separator("Color options:")
|
59
59
|
|
60
|
-
options.on("-
|
61
|
-
|
60
|
+
options.on("-iCOLOR", "--interactive-color=COLOR", "Disable color rendering for interactive buffer (Default: #{(defaults.interactive_color).inspect})") do |interactive_color|
|
61
|
+
if ["false", "f" ,"no", "n"].include?(interactive_color.downcase)
|
62
|
+
config[:interactive_color] = false
|
63
|
+
else
|
64
|
+
config[:interactive_color] = interactive_color
|
65
|
+
end
|
62
66
|
end
|
63
67
|
|
64
|
-
options.on("-
|
68
|
+
options.on("-oCOLOR", "--with-output-color=COLOR", "Enable color rendering for output buffer (Default: #{(defaults.output_color).inspect})") do |output_color|
|
65
69
|
config[:output_color] = output_color
|
66
70
|
end
|
67
71
|
|
data/lib/gm/notepad/app.rb
CHANGED
@@ -15,6 +15,9 @@ module Gm
|
|
15
15
|
|
16
16
|
def initialize(*args, input_processor: nil, renderer: nil)
|
17
17
|
super
|
18
|
+
# Note: I could note use Dry::Initializer.option with Container as I ended
|
19
|
+
# up with multiple table registry objects created. Which is why I'm using the
|
20
|
+
# keyword's with nil, so I can set two elements after the table_registry is "resolved"
|
18
21
|
@renderer = renderer || LineRenderer.new(table_registry: table_registry)
|
19
22
|
@input_processor = input_processor || InputProcessor.new(table_registry: table_registry)
|
20
23
|
open!
|
data/lib/gm/notepad/config.rb
CHANGED
@@ -17,7 +17,7 @@ module Gm
|
|
17
17
|
setting :report_config, false, reader: true
|
18
18
|
setting :skip_readlines, false, reader: true
|
19
19
|
setting :table_extension, '.txt', reader: true
|
20
|
-
setting :time_to_live,
|
20
|
+
setting :time_to_live, 100, reader: true
|
21
21
|
setting :with_timestamp, false, reader: true
|
22
22
|
|
23
23
|
def self.index_entry_prefix_regexp
|
@@ -4,37 +4,24 @@ module Gm
|
|
4
4
|
module Notepad
|
5
5
|
module InputHandlers
|
6
6
|
class WriteToTableHandler < DefaultHandler
|
7
|
-
|
7
|
+
WITH_WRITE_TARGET_REGEXP = %r{\A\<(?<table_name>[^:]+):(?<line>.*)}
|
8
8
|
def self.handles?(input:)
|
9
|
-
return true if input.match(
|
9
|
+
return true if input.match(WITH_WRITE_TARGET_REGEXP)
|
10
10
|
end
|
11
11
|
|
12
|
-
NON_EXPANDING_CHARATER = '!'.freeze
|
13
|
-
WITH_INDEX_REGEXP = %r{(?<declaration>\[(?<index>[^\]]+)\])}
|
14
|
-
WITH_GREP_REGEXP = %r{(?<declaration>\/(?<grep>[^\/]+)/)}
|
15
|
-
WITH_WRITE_TARGET_REGEXP = %r{\A#{HANDLED_PREFIX}(?<table_name>[^:]+):(?<line>.*)}
|
16
12
|
def after_initialize!
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
raise "I don't know what to do"
|
30
|
-
end
|
31
|
-
if input.match(/^\!/)
|
32
|
-
expand_line = false
|
33
|
-
input.sub!(/^\!/, '')
|
34
|
-
else
|
35
|
-
expand_line = true
|
36
|
-
end
|
37
|
-
input.for_rendering(table_name: table_name, text: input.text_to_evaluate, to_interactive: true , to_output: false, to_filesystem: true, expand_line: expand_line)
|
13
|
+
match = input.match(WITH_WRITE_TARGET_REGEXP)
|
14
|
+
input.text_to_evaluate = match[:line].strip
|
15
|
+
table_name = match[:table_name]
|
16
|
+
table_name = table_name.downcase
|
17
|
+
input.for_rendering(
|
18
|
+
table_name: table_name,
|
19
|
+
text: input.text_to_evaluate,
|
20
|
+
to_interactive: true,
|
21
|
+
to_output: false,
|
22
|
+
to_filesystem: true,
|
23
|
+
expand_line: true
|
24
|
+
)
|
38
25
|
end
|
39
26
|
end
|
40
27
|
end
|
@@ -35,32 +35,25 @@ module Gm
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
CELL_AND_INDEX_DECLARED_REGEXP = %r{(?<declaration>\[(?<index>[^\[\]]*)\]\[(?<cell>[^\[\]]*)\])}
|
39
|
+
|
38
40
|
WITH_GREP_REGEXP = %r{(?<declaration>\/(?<found>[^\/]+)/)}
|
39
41
|
WITH_INDEX_REGEXP = %r{(?<declaration>\[(?<found>[^\]]+)\])}
|
40
|
-
CELL_WITHOUT_INDEX_REGEXP = %r{(?<declaration>\[\]\[(?<found>[^\]]+)\])}
|
41
|
-
EMPTY_INDEX_EMPTY_CELL_REGEXP = %r{(?<declaration>\[\]\[\])}
|
42
42
|
WITH_EMPTY_INDEX_REGEX = %r{(?<declaration>\[\])}
|
43
43
|
WITH_EMPTY_GREP_REGEX = %r{(?<declaration>\/\/)}
|
44
44
|
|
45
|
+
# TODO: Revisit this method to see if I can remove some pre-amble
|
45
46
|
def extract_parameters!
|
46
47
|
text = @text
|
47
|
-
if match =
|
48
|
-
|
49
|
-
|
48
|
+
if match = CELL_AND_INDEX_DECLARED_REGEXP.match(text)
|
49
|
+
self.index = match[:index] if match[:index].present?
|
50
|
+
self.cell = match[:cell] if match[:cell].present?
|
50
51
|
text = text.sub(match[:declaration], '')
|
51
|
-
self.cell = match[:found]
|
52
52
|
elsif match = WITH_EMPTY_INDEX_REGEX.match(text)
|
53
53
|
text = text.sub(match[:declaration], '')
|
54
54
|
elsif match = WITH_INDEX_REGEXP.match(text)
|
55
55
|
text = text.sub(match[:declaration], '')
|
56
56
|
self.index = match[:found]
|
57
|
-
# Moving on to the cell
|
58
|
-
if match = WITH_EMPTY_INDEX_REGEX.match(text)
|
59
|
-
text = text.sub(match[:declaration], '')
|
60
|
-
elsif match = WITH_INDEX_REGEXP.match(text)
|
61
|
-
text = text.sub(match[:declaration], '')
|
62
|
-
self.cell = match[:found]
|
63
|
-
end
|
64
57
|
elsif match = WITH_EMPTY_GREP_REGEX.match(text)
|
65
58
|
text = text.sub(match[:declaration], '')
|
66
59
|
elsif match = WITH_GREP_REGEXP.match(text)
|
data/lib/gm/notepad/table.rb
CHANGED
@@ -8,7 +8,7 @@ module Gm
|
|
8
8
|
module Notepad
|
9
9
|
class Table
|
10
10
|
extend Dry::Initializer
|
11
|
-
option :table_name,
|
11
|
+
option :table_name, -> (value) { value.to_s.downcase.strip }
|
12
12
|
option :filename, optional: true
|
13
13
|
option :lines, type: method(:Array)
|
14
14
|
option :index_entry_prefix_regexp, default: -> { Container.resolve(:config).index_entry_prefix_regexp }
|
@@ -93,13 +93,6 @@ module Gm
|
|
93
93
|
@table.values[random_index]
|
94
94
|
end
|
95
95
|
|
96
|
-
attr_accessor :filename
|
97
|
-
attr_reader :table_name
|
98
|
-
|
99
|
-
def table_name=(input)
|
100
|
-
@table_name = input.downcase
|
101
|
-
end
|
102
|
-
|
103
96
|
def random_index
|
104
97
|
rand(@table.size)
|
105
98
|
end
|
@@ -36,7 +36,13 @@ module Gm
|
|
36
36
|
|
37
37
|
def lookup(cell:)
|
38
38
|
index = table.column_index_for(cell: cell)
|
39
|
-
|
39
|
+
if index.nil?
|
40
|
+
# In the file, we have cell 0 is the index. This is hidden from the cell lookup, so I
|
41
|
+
# want to internally treat the given cell as one less.
|
42
|
+
cells[cell.to_i - 1]
|
43
|
+
else
|
44
|
+
cells[index] || cells[0]
|
45
|
+
end
|
40
46
|
end
|
41
47
|
|
42
48
|
NUMBER_RANGE_REGEXP = %r{(?<left>\d+) *- *(?<right>\d+)}
|
data/lib/gm/notepad/version.rb
CHANGED