l43_rmap 0.1.3 → 0.1.4
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/lib/l43_rmap/cli/color.rb +1 -1
- data/lib/l43_rmap/cli.rb +3 -3
- data/lib/l43_rmap/runtime.rb +10 -4
- data/lib/l43_rmap/version.rb +1 -1
- data/lib/l43_rmap.rb +2 -2
- 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: d55c3692c807fd46a368f265ddfb492640c44e134cfcd56660d831482612191e
|
|
4
|
+
data.tar.gz: 25c329e6544381cb52b5b386e7fe73d62c00c14d9e7179de9f324a952846f4a2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 99ba2278ccd9f935472b12b4c983147255e3daeebfc3084000e6229a86db1fd7c8b71fb544b04707d171517ee7bb46e364955a711613e13e3793099d7c513319
|
|
7
|
+
data.tar.gz: 966bc037f9c52c256debfc74682e8b05ce2bf90bc9381afc54a808dff5d912e10caef3628b6fb03410b825433c3e42ab123dce78cc3924329ff71599e62cf36f
|
data/lib/l43_rmap/cli/color.rb
CHANGED
|
@@ -5,7 +5,7 @@ module L43Rmap
|
|
|
5
5
|
module Color
|
|
6
6
|
def arg(name) = [:bold, :blue, "<#{name}>", :reset]
|
|
7
7
|
def arg1(name) = [:bold, :blue, name, :reset]
|
|
8
|
-
def dimmed(
|
|
8
|
+
def dimmed(*chunks) = [:dim, "(", *chunks, ")", :reset]
|
|
9
9
|
|
|
10
10
|
def kwd(name) = [" kwd ", :bold, :cyan, name, ":", :reset]
|
|
11
11
|
|
data/lib/l43_rmap/cli.rb
CHANGED
|
@@ -27,7 +27,7 @@ module L43Rmap
|
|
|
27
27
|
private
|
|
28
28
|
def initialize
|
|
29
29
|
parser
|
|
30
|
-
.usage("rmap", options: true, args: 'pattern')
|
|
30
|
+
.usage("rmap", dimmed(version_string), " ", options: true, args: 'pattern')
|
|
31
31
|
parser
|
|
32
32
|
.section("Flags")
|
|
33
33
|
.flag(:compile_only, :c, desc: ["Only compile ", :bold, :blue, "pattern"])
|
|
@@ -41,13 +41,13 @@ module L43Rmap
|
|
|
41
41
|
.flag(:version, :v, desc: ["Just print current version ",dimmed(version_string)], stop: true)
|
|
42
42
|
.section("Options")
|
|
43
43
|
.keyword(:input, :i, desc: ["file to read from, defaults to ", :bold, :cyan, '$stdin'], default: $stdin)
|
|
44
|
+
.keyword(:limit, :l, desc:["if specified, limits output to the given value of lines, it is applied, ", :bold, "after", :reset, " randomization (if applicable)"], default: nil, &:to_i)
|
|
44
45
|
.keyword(:output, :o, desc: ["file to write to, defaults to ", :bold, :cyan, '$stdout'], default: $stdout)
|
|
45
46
|
.keyword(:pattern, desc: ["use a predefined pattern instead of positional argument. ", :bold, "Conflicts with ", :blue, "pattern"], default: nil)
|
|
46
|
-
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def _compile
|
|
50
|
-
@runtime = L43Rmap.compile(pattern)
|
|
50
|
+
@runtime = L43Rmap.compile(pattern, limit: kwds.limit)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def _run
|
data/lib/l43_rmap/runtime.rb
CHANGED
|
@@ -6,7 +6,7 @@ require_relative 'runtime/line_time'
|
|
|
6
6
|
module L43Rmap
|
|
7
7
|
class Runtime
|
|
8
8
|
# attr_reader :chunks, :current, :input_stream, :output_stream, :rand, :randomize, :terminated, :time
|
|
9
|
-
attr_reader :chunks, :current, :input_stream, :output_stream, :randomize, :terminated, :time
|
|
9
|
+
attr_reader :chunks, :current, :input_stream, :limit, :output_stream, :randomize, :terminated, :time
|
|
10
10
|
|
|
11
11
|
DefaultDecRandomMax = 10_000
|
|
12
12
|
|
|
@@ -60,8 +60,9 @@ module L43Rmap
|
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
def initialize(chunks)
|
|
63
|
+
def initialize(chunks, limit: nil)
|
|
64
64
|
@chunks = chunks
|
|
65
|
+
@limit = limit || -1
|
|
65
66
|
end
|
|
66
67
|
|
|
67
68
|
def make_input_stream(stream)
|
|
@@ -77,9 +78,12 @@ module L43Rmap
|
|
|
77
78
|
def maybe_output_buffer
|
|
78
79
|
return unless randomize
|
|
79
80
|
|
|
80
|
-
output_buffer
|
|
81
|
+
sorted = output_buffer
|
|
81
82
|
.sort_by { rand }
|
|
82
|
-
|
|
83
|
+
# p(sorted:)
|
|
84
|
+
sorted.each do
|
|
85
|
+
raise EOFError, "limit reached" if limit.zero?
|
|
86
|
+
@limit -= 1
|
|
83
87
|
output_stream << it
|
|
84
88
|
output_stream << "\n"
|
|
85
89
|
end
|
|
@@ -91,6 +95,8 @@ module L43Rmap
|
|
|
91
95
|
if randomize
|
|
92
96
|
output_buffer << line
|
|
93
97
|
else
|
|
98
|
+
raise EOFError, "limit reached" if limit.zero?
|
|
99
|
+
@limit -= 1
|
|
94
100
|
output_stream << line
|
|
95
101
|
output_stream << "\n"
|
|
96
102
|
end
|
data/lib/l43_rmap/version.rb
CHANGED
data/lib/l43_rmap.rb
CHANGED
|
@@ -21,10 +21,10 @@ module L43Rmap
|
|
|
21
21
|
]
|
|
22
22
|
|
|
23
23
|
class << self
|
|
24
|
-
def compile(pattern)
|
|
24
|
+
def compile(pattern, limit: nil)
|
|
25
25
|
ast = Parsing::ChunkParser.new.parse(pattern)
|
|
26
26
|
chunks = Compiler.new.compile(ast)
|
|
27
|
-
Runtime.new(chunks)
|
|
27
|
+
Runtime.new(chunks, limit: limit || -1)
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
end
|