gm-notepad 0.0.8 → 0.0.9
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 +4 -4
- data/README.md +6 -7
- data/Rakefile +1 -1
- data/lib/gm/notepad/configuration.rb +1 -0
- data/lib/gm/notepad/line_renderer.rb +12 -2
- data/lib/gm/notepad/table.rb +36 -7
- data/lib/gm/notepad/table_column_set.rb +33 -0
- data/lib/gm/notepad/table_entry.rb +1 -1
- data/lib/gm/notepad/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: de7a4c2dc05bae568e9f8c5d98644495563447a55cc9ff6af4b53199ffe64311
|
|
4
|
+
data.tar.gz: d1a469f3379acc8213ae64050457473186411359af8ce707b7f8ac267d6749d2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da07a6915adf85b592a7d0b6b0280573da0b9f802b4c148684eef38896f72570b5c5ac2855ab938691dc0ab49aa8d49cfee34abcd590249d9e0fd08bef3fb209
|
|
7
|
+
data.tar.gz: 70b13268f20d7b2cfca3c18288f9f853a5bf2a506132aa8558ce7ab4b931a0d98af8a487b2d8b261514dd812fd30d98170d2c82a101d9e2fcb7e1b8253fe07ec
|
data/README.md
CHANGED
|
@@ -189,14 +189,12 @@ Frodo owes 3gp to SamWise
|
|
|
189
189
|
```
|
|
190
190
|
|
|
191
191
|
Let's take a look at the `+character` table. Your table indices need not be
|
|
192
|
-
numbers. And you can mix numbers and text.
|
|
193
|
-
|
|
194
|
-
entry has a 1 in 3 chance of being randomly chosen.
|
|
192
|
+
numbers. And you can mix numbers and text. This example introduces the idea of
|
|
193
|
+
columns. _I am still working on retrieving by column names as well as rendering column names_.
|
|
195
194
|
|
|
196
195
|
```console
|
|
197
|
-
=> [
|
|
198
|
-
=> [
|
|
199
|
-
=> [hd] 12D12
|
|
196
|
+
=> [grell] Grell 15 12D12
|
|
197
|
+
=> [jehat] Jehat 19 14D6
|
|
200
198
|
```
|
|
201
199
|
|
|
202
200
|
## Testing Locally
|
|
@@ -228,7 +226,7 @@ entry has a 1 in 3 chance of being randomly chosen.
|
|
|
228
226
|
- [X] Add index name when rendering table entries
|
|
229
227
|
- [ ] Gracefully handle loading a malformed data file (maybe?)
|
|
230
228
|
- [X] Add concept of history
|
|
231
|
-
- [
|
|
229
|
+
- [X] When expanding tables account for line expansion (via \n and \t)
|
|
232
230
|
- [ ] Separate the InputHandler into pre-amble (e.g. allow overrides to where we are writing, determine what command we are writing)
|
|
233
231
|
- [X] Create a configuration object that captures the initial input (reduce passing around parameters and persisting copies of the config)
|
|
234
232
|
- [ ] Add concept of "journal entry"; its not a table (perhaps) but something that you could capture notes.
|
|
@@ -237,6 +235,7 @@ entry has a 1 in 3 chance of being randomly chosen.
|
|
|
237
235
|
- [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
|
|
238
236
|
- [X] Ensure index names are lower-case
|
|
239
237
|
- [ ] Hit 100% spec coverage
|
|
238
|
+
- [ ] 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.
|
|
240
239
|
|
|
241
240
|
### Stretch TODO
|
|
242
241
|
|
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
|
|
@@ -39,7 +39,7 @@ module Gm
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def render_output(lines, defer_output:, as_of:)
|
|
42
|
-
|
|
42
|
+
each_expanded_line(lines: lines) do |line|
|
|
43
43
|
if config[:with_timestamp]
|
|
44
44
|
line = "#{as_of}\t#{line}"
|
|
45
45
|
end
|
|
@@ -52,10 +52,20 @@ module Gm
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def render_interactive(lines)
|
|
55
|
-
|
|
55
|
+
each_expanded_line(lines: lines) do |line|
|
|
56
56
|
interactive_buffer.puts("=>\t#{line}")
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
|
+
|
|
60
|
+
# Gracefully expand the \t and \n for the output buffer
|
|
61
|
+
def each_expanded_line(lines:)
|
|
62
|
+
Array(lines).each do |unexpanded_line|
|
|
63
|
+
unexpanded_line.to_s.split('\\n').each do |line|
|
|
64
|
+
line = line.gsub('\\t', "\t")
|
|
65
|
+
yield(line)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
59
69
|
end
|
|
60
70
|
|
|
61
71
|
# To provide a means for colorizing the output
|
data/lib/gm/notepad/table.rb
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
require "gm/notepad/exceptions"
|
|
2
|
+
require "gm/notepad/configuration"
|
|
2
3
|
require "gm/notepad/table_entry"
|
|
4
|
+
require "gm/notepad/table_column_set"
|
|
3
5
|
|
|
4
6
|
module Gm
|
|
5
7
|
module Notepad
|
|
6
8
|
class Table
|
|
7
|
-
Configuration.init!(target: self, additional_params: [:table_name, :filename, :lines]) do
|
|
9
|
+
Configuration.init!(target: self, from_config: [:column_delimiter, :index_entry_prefix], additional_params: [:table_name, :filename, :lines]) do
|
|
10
|
+
@index_entry_prefix_regexp = %r{^#{Regexp.escape(index_entry_prefix)} *#{Regexp.escape(column_delimiter)}}i.freeze
|
|
11
|
+
set_null_table_column_set!
|
|
8
12
|
process(lines: lines)
|
|
9
13
|
end
|
|
10
14
|
|
|
@@ -24,6 +28,10 @@ module Gm
|
|
|
24
28
|
@table.values.uniq
|
|
25
29
|
end
|
|
26
30
|
|
|
31
|
+
def column_names
|
|
32
|
+
@table_column_set.names
|
|
33
|
+
end
|
|
34
|
+
|
|
27
35
|
def grep(expression)
|
|
28
36
|
returning_value = []
|
|
29
37
|
@table.each_value do |entry|
|
|
@@ -68,18 +76,39 @@ module Gm
|
|
|
68
76
|
rand(@table.size)
|
|
69
77
|
end
|
|
70
78
|
|
|
79
|
+
STARTS_WITH_COMMENT_REGEXP = %r{\A#}
|
|
71
80
|
def process(lines:)
|
|
72
81
|
@table = {}
|
|
73
82
|
lines.each do |line|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
line = line.strip
|
|
84
|
+
# Handle Comment
|
|
85
|
+
case line
|
|
86
|
+
when STARTS_WITH_COMMENT_REGEXP
|
|
87
|
+
next
|
|
88
|
+
when @index_entry_prefix_regexp
|
|
89
|
+
register_index_declaration!(line: line)
|
|
90
|
+
else
|
|
91
|
+
make_entry!(line: line)
|
|
80
92
|
end
|
|
81
93
|
end
|
|
82
94
|
end
|
|
95
|
+
|
|
96
|
+
def set_null_table_column_set!
|
|
97
|
+
@table_column_set = TableColumnSet::Null.new
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def register_index_declaration!(line:)
|
|
101
|
+
@table_column_set = TableColumnSet.new(table: self, line: line, config: config)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def make_entry!(line:)
|
|
105
|
+
entry = TableEntry.new(table: self, line: line, config: config)
|
|
106
|
+
entry.lookup_range.each do |i|
|
|
107
|
+
key = i.to_s
|
|
108
|
+
raise DuplicateKeyError.new(key: table_name, object: self) if @table.key?(key)
|
|
109
|
+
@table[key] = entry
|
|
110
|
+
end
|
|
111
|
+
end
|
|
83
112
|
end
|
|
84
113
|
end
|
|
85
114
|
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "gm/notepad/exceptions"
|
|
2
|
+
require "gm/notepad/configuration"
|
|
3
|
+
|
|
4
|
+
module Gm
|
|
5
|
+
module Notepad
|
|
6
|
+
class TableColumnSet
|
|
7
|
+
# Because we may not have an index row, from which we create a TableColumnSet.
|
|
8
|
+
# So this class provides the necessary external interface.
|
|
9
|
+
class Null
|
|
10
|
+
def names
|
|
11
|
+
[]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Configuration.init!(target: self, additional_params: [:table, :line], from_config: [:column_delimiter]) do
|
|
16
|
+
@columns = []
|
|
17
|
+
@index =
|
|
18
|
+
process_line!
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def names
|
|
22
|
+
@columns.map(&:to_s)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
def process_line!
|
|
27
|
+
columns = line.split(column_delimiter)
|
|
28
|
+
@index = columns.shift
|
|
29
|
+
@columns = columns.map {|c| c.strip.downcase }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -3,7 +3,7 @@ module Gm
|
|
|
3
3
|
module Notepad
|
|
4
4
|
TABLE_ENTRY_RANGE_MARKER = "-".freeze
|
|
5
5
|
class TableEntry
|
|
6
|
-
Configuration.init!(target: self, from_config: [:column_delimiter], additional_params: [:line]) do
|
|
6
|
+
Configuration.init!(target: self, from_config: [:column_delimiter], additional_params: [:line, :table]) do
|
|
7
7
|
row = line.split(column_delimiter)
|
|
8
8
|
self.index = row.shift
|
|
9
9
|
self.cells = row
|
data/lib/gm/notepad/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeremy Friesen
|
|
@@ -163,6 +163,7 @@ files:
|
|
|
163
163
|
- lib/gm/notepad/parameters/table_lookup.rb
|
|
164
164
|
- lib/gm/notepad/readline.rb
|
|
165
165
|
- lib/gm/notepad/table.rb
|
|
166
|
+
- lib/gm/notepad/table_column_set.rb
|
|
166
167
|
- lib/gm/notepad/table_entry.rb
|
|
167
168
|
- lib/gm/notepad/table_registry.rb
|
|
168
169
|
- lib/gm/notepad/version.rb
|