l42_my_ruby 0.1.6 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/l42/interfaces/map_inp/pattern_mapper.rb +82 -0
- data/lib/l42/interfaces/map_inp/rgx_filter.rb +32 -0
- data/lib/l42/interfaces/map_inp.rb +9 -31
- data/lib/l42/version.rb +1 -1
- data/lib/l42.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a464749bc08c5eac3d31ace8fbb907cc7e1917bcea302f6f53d38349c61e11f5
|
4
|
+
data.tar.gz: 67a4827978271d5531737e698bb14849135064be9be7e470e61a3d6678fd426a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bf21643874e5aa122283c89d751200fca21ff5d3f330e1d07d5f82d917daae8994d24e5d8e6e05fb0d6a2c0bda1906dfdf6e4021dcfa06cd229153f8876152d
|
7
|
+
data.tar.gz: 875f46e3d1c3165f657f7b2af730d770088cf506592346152fe90bb0d27dd0d1072721a9f03963fc4a7eb491687558dae61de441a8711ab56bf66696ce00019f
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module L42
|
4
|
+
module Interfaces
|
5
|
+
module MapInp
|
6
|
+
module PatternMapper
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def run(input, pattern, options)
|
10
|
+
options[:sep] = "\u0000" if options[:"0"]
|
11
|
+
_compile(pattern, options) => pattern, options, field_rgxn
|
12
|
+
|
13
|
+
[
|
14
|
+
:stdout,
|
15
|
+
input.each_with_index.map(&_map(pattern, options, field_rgxn))
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
Count = %r{(?<!%)%c}
|
22
|
+
FieldId = %r{(?<!%)%(\d+)}
|
23
|
+
FormattedCount = %r{(?<!%)%f(\d+)}
|
24
|
+
Now = %r{(?<!%)%x}
|
25
|
+
Replacer = %r{(?<!%)%(?!%)}
|
26
|
+
|
27
|
+
def _compile(pattern, options)
|
28
|
+
pattern = pattern.gsub(Now, Time.now.to_i.to_s(16))
|
29
|
+
|
30
|
+
max_field = pattern.scan(FieldId).flatten.map(&:to_i).max
|
31
|
+
options[:max_field] = max_field
|
32
|
+
field_rgxen =
|
33
|
+
(1..max_field||0).map { |nb| %r{(?<!%)%#{nb}(?!\d)} }
|
34
|
+
[pattern, options, field_rgxen]
|
35
|
+
end
|
36
|
+
|
37
|
+
def _map(pattern, options, field_rgxen)
|
38
|
+
->(record, idx) do
|
39
|
+
_transform_inp(pattern, record, idx, options, field_rgxen)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def _replace_formatted(idx)
|
44
|
+
->match_str do
|
45
|
+
"%0#{match_str[2..]}d" % idx
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def _transform_inp(pattern, record, idx, options, field_rgxen)
|
50
|
+
if options[:max_field]
|
51
|
+
_transform_splitting(pattern, record, idx, options, field_rgxen)
|
52
|
+
else
|
53
|
+
_transform_plain(pattern, record, idx)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def _transform_plain(pattern, record, idx)
|
58
|
+
pattern
|
59
|
+
.gsub(Count, idx.to_s)
|
60
|
+
.gsub(FormattedCount, &_replace_formatted(idx))
|
61
|
+
.gsub(Replacer, record)
|
62
|
+
.gsub("%%", "%")
|
63
|
+
end
|
64
|
+
|
65
|
+
def _transform_splitting(pattern, record, idx, options, field_rgxn)
|
66
|
+
fields = record.split(options[:sep]||%r{\s+}, options[:max_field].succ)
|
67
|
+
output = pattern
|
68
|
+
.gsub(Count, idx.to_s)
|
69
|
+
.gsub(FormattedCount, &_replace_formatted(idx))
|
70
|
+
|
71
|
+
output = (0...options[:max_field]).inject(output) do |out, field_nb|
|
72
|
+
out.gsub(field_rgxn[field_nb], fields[field_nb])
|
73
|
+
end
|
74
|
+
output
|
75
|
+
.gsub(Replacer, record)
|
76
|
+
.gsub("%%", "%")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module L42
|
4
|
+
module Interfaces
|
5
|
+
module MapInp
|
6
|
+
module RgxFilter
|
7
|
+
extend self
|
8
|
+
def run(input, rgx_str, options)
|
9
|
+
rgx = Regexp.compile(rgx_str)
|
10
|
+
options[:sep] = "\u0000" if options.to_h[:"0"]
|
11
|
+
[
|
12
|
+
:stdout,
|
13
|
+
input.filter_map(&_match_and_patterns(rgx, options))
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def _match_and_patterns(rgx, options)
|
20
|
+
->record do
|
21
|
+
if match = rgx.match(record)
|
22
|
+
match.to_a => _, *captures
|
23
|
+
[record, *captures].join(options.to_h.fetch(:sep, " "))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -1,45 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'securerandom'
|
4
|
+
require 'lab42/rgxargs'
|
5
|
+
|
4
6
|
module L42
|
5
7
|
module Interfaces
|
6
8
|
module MapInp
|
7
9
|
extend self
|
8
10
|
|
9
|
-
def call(input,
|
10
|
-
|
11
|
-
|
12
|
-
:stdout,
|
13
|
-
input.each_with_index.map(&_map(pattern))
|
14
|
-
]
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
11
|
+
def call(input, *args)
|
12
|
+
parser = Lab42::Rgxargs.new(posix: true)
|
13
|
+
parser.parse(args) => options, positionals, _
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def _map(pattern)
|
25
|
-
->(record, idx) do
|
26
|
-
_transform_inp(pattern, record, idx)
|
15
|
+
if options.r
|
16
|
+
RgxFilter.run(input, positionals.first, options)
|
17
|
+
else
|
18
|
+
PatternMapper.run(input, positionals.first, options)
|
27
19
|
end
|
28
20
|
end
|
29
|
-
|
30
|
-
def _replace_formatted(idx)
|
31
|
-
->match_str do
|
32
|
-
"%0#{match_str[2..]}d" % idx
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def _transform_inp(pattern, record, idx)
|
37
|
-
pattern
|
38
|
-
.gsub(Count, idx.to_s)
|
39
|
-
.gsub(FormattedCount, &_replace_formatted(idx))
|
40
|
-
.gsub(Replacer, record)
|
41
|
-
.gsub("%%", "%")
|
42
|
-
end
|
43
21
|
end
|
44
22
|
end
|
45
23
|
end
|
data/lib/l42/version.rb
CHANGED
data/lib/l42.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: l42_my_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lab42_rgxargs
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.
|
19
|
+
version: 0.2.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.2.
|
26
|
+
version: 0.2.2
|
27
27
|
description: |
|
28
28
|
All my Ruby Code
|
29
29
|
|
@@ -48,6 +48,8 @@ files:
|
|
48
48
|
- lib/l42.rb
|
49
49
|
- lib/l42/data_class.rb
|
50
50
|
- lib/l42/interfaces/map_inp.rb
|
51
|
+
- lib/l42/interfaces/map_inp/pattern_mapper.rb
|
52
|
+
- lib/l42/interfaces/map_inp/rgx_filter.rb
|
51
53
|
- lib/l42/interfaces/pfx_by_now.rb
|
52
54
|
- lib/l42/interfaces/to_random.rb
|
53
55
|
- lib/l42/interfaces/tx_send.rb
|