l42_my_ruby 0.1.4 → 0.2.1

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: 1781982f07cea572f852c3a439fe867c61140a78ddcff1ee521188a60d8a97ba
4
- data.tar.gz: 754a7ff931346db195b9d25fc1adf8cc63661101527ba8139e46147a36bb207e
3
+ metadata.gz: a464749bc08c5eac3d31ace8fbb907cc7e1917bcea302f6f53d38349c61e11f5
4
+ data.tar.gz: 67a4827978271d5531737e698bb14849135064be9be7e470e61a3d6678fd426a
5
5
  SHA512:
6
- metadata.gz: 871de02165537b8076e4280371c91db464d16f4c56e1acf52fcefcfc800d2f8d7ee735e0ea9847e70a7233241d2c64a1044e1b1db5df113933dd86611d91e855
7
- data.tar.gz: 4f81c78b9444c3e129d18dda9c4f60743eb7993e1730021bf92bb99bcb67faedcbdaa6320afd66f21a36039daa0352a14e757ee52c93e667b3e86e67fc5eedda
6
+ metadata.gz: 9bf21643874e5aa122283c89d751200fca21ff5d3f330e1d07d5f82d917daae8994d24e5d8e6e05fb0d6a2c0bda1906dfdf6e4021dcfa06cd229153f8876152d
7
+ data.tar.gz: 875f46e3d1c3165f657f7b2af730d770088cf506592346152fe90bb0d27dd0d1072721a9f03963fc4a7eb491687558dae61de441a8711ab56bf66696ce00019f
data/bin/map_inp ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/l42'
5
+
6
+ L42::Monad.interact(L42::Interfaces::MapInp, *ARGV)
7
+ # SPDX-License-Identifier: Apache-2.0
data/bin/mv_pfx_by_now ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/l42'
5
+
6
+ L42::Monad.interact(L42::Interfaces::PfxByNow)
7
+ # SPDX-License-Identifier: Apache-2.0
@@ -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
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ require 'lab42/rgxargs'
5
+
6
+ module L42
7
+ module Interfaces
8
+ module MapInp
9
+ extend self
10
+
11
+ def call(input, *args)
12
+ parser = Lab42::Rgxargs.new(posix: true)
13
+ parser.parse(args) => options, positionals, _
14
+
15
+ if options.r
16
+ RgxFilter.run(input, positionals.first, options)
17
+ else
18
+ PatternMapper.run(input, positionals.first, options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ module L42
5
+ module Interfaces
6
+ module PfxByNow
7
+ extend self
8
+
9
+ def call(files)
10
+ now = Time.now.to_i.to_s(16)
11
+ [
12
+ :stdout,
13
+ files.map(&_pfx_by_now(now))
14
+ ]
15
+ end
16
+
17
+ private
18
+
19
+ def _pfx_by_now(now)
20
+ ->file do
21
+ ["mv", file.inspect, [now, file].join("_").inspect ].join(" ")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ # SPDX-License-Identifier: Apache-2.0
data/lib/l42/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module L42
4
4
  module Version
5
- VERSION = '0.1.4'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: Apache-2.0
data/lib/l42.rb CHANGED
@@ -5,8 +5,8 @@ loader = Zeitwerk::Loader.for_gem
5
5
  loader.setup # ready!
6
6
  # loader.eager_load # optionally
7
7
 
8
+ require_relative "l42/version"
8
9
  module L42
9
- # ...
10
10
  end
11
11
 
12
12
  # SPDX-License-Identifier: Apache-2.0
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
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-27 00:00:00.000000000 Z
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,20 +16,22 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.1
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.1
26
+ version: 0.2.2
27
27
  description: |
28
28
  All my Ruby Code
29
29
 
30
30
  Binaries and libs which make Ruby awesome (for me)
31
31
  email: robert.dober@gmail.com
32
32
  executables:
33
+ - map_inp
34
+ - mv_pfx_by_now
33
35
  - mv_to_random
34
36
  - mv_with_ts
35
37
  - tx_send
@@ -38,11 +40,17 @@ extra_rdoc_files: []
38
40
  files:
39
41
  - LICENSE
40
42
  - README.md
43
+ - bin/map_inp
44
+ - bin/mv_pfx_by_now
41
45
  - bin/mv_to_random
42
46
  - bin/mv_with_ts
43
47
  - bin/tx_send
44
48
  - lib/l42.rb
45
49
  - lib/l42/data_class.rb
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
53
+ - lib/l42/interfaces/pfx_by_now.rb
46
54
  - lib/l42/interfaces/to_random.rb
47
55
  - lib/l42/interfaces/tx_send.rb
48
56
  - lib/l42/interfaces/with_ts.rb
@@ -52,7 +60,7 @@ homepage: https://github.com/robertdober/l42_my_ruby
52
60
  licenses:
53
61
  - Apache-2.0
54
62
  metadata: {}
55
- post_install_message:
63
+ post_install_message:
56
64
  rdoc_options: []
57
65
  require_paths:
58
66
  - lib
@@ -68,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
76
  version: '0'
69
77
  requirements: []
70
78
  rubygems_version: 3.3.7
71
- signing_key:
79
+ signing_key:
72
80
  specification_version: 4
73
81
  summary: All my Ruby Code
74
82
  test_files: []