l42_my_ruby 0.1.3 → 0.1.6

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: bb1c3756379e743210148854ee4eedb3e3a15e8d009051a5e1b43083fde80715
4
- data.tar.gz: 668781958b9b1caf7721896b5e3a8f05a94e7409f259223db4fb8ae842f3c311
3
+ metadata.gz: 8a762c688eb1bbaa6420cfb79a6268bb4443d972ac1b68c6083fe617e4e0c4a8
4
+ data.tar.gz: 0e722cc52df7fa8c8c99f2be71403701d6f7c04b954306fca3ccae062377cf64
5
5
  SHA512:
6
- metadata.gz: 9ca6caf9ffeb117ee01dcfca54072db7ea5e402be9d62e782abce90b3470bc4f8897e7bbf150f3afeaf09c0eaebc2fe4520b9be6e38180eb3eaa935534212b5c
7
- data.tar.gz: 636cac32842376ad0cd33c1ad292e2aa8cff03a033379304f75931f11a01b42c4914636635aa97f8444a7589de6a427a3ff8fa18b6bc7639a2027667f3e8705c
6
+ metadata.gz: 790d92485477fd06231991265cfe43f6a72278aaa348d0a51e5e2d5c69da982315dd9e52cd61d28052b16d95682cd43c047dd86be8026ff97f28e597eaff6bcb
7
+ data.tar.gz: 41b618d3238f06f5d301f10cfbb1a3c80672d54fd7b3c9c3d138699e6f265036ff9ad8fb3a7e4595a3d3d3104db204eb511536bbe9d7a7fa96126d30693b4abc
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  [![CI](https://github.com/robertdober/l42_my_ruby/workflows/CI/badge.svg)](https://github.com/robertdober/l42_my_ruby/actions)
2
- [![Coverage Status](https://coveralls.io/repos/github/RobertDober/l42_my_ruby/badge.svg?branch=main)](https://coveralls.io/github/RobertDober/l42_my_ruby?branch=main)
3
- [![Gem Version](http://img.shields.io/gem/v/l42.svg)](https://rubygems.org/gems/l42_my_ruby)
4
- [![Gem Downloads](https://img.shields.io/gem/dt/l42.svg)](https://rubygems.org/gems/l42_my_ruby)
2
+ [![Coverage Status](https://coveralls.io/repos/github/RobertDober/l42_my_ruby/badge.svg?branch=master)](https://coveralls.io/github/RobertDober/l42_my_ruby?branch=master)
3
+ [![Gem Version](https://badge.fury.io/rb/l42_my_ruby.svg)](http://badge.fury.io/rb/l42_my_ruby)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/l42_my_ruby.svg)](https://rubygems.org/gems/l42_my_ruby)
5
5
 
6
6
  # L42MyRuby
7
7
 
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
data/bin/tx_send CHANGED
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  require_relative '../lib/l42'
4
5
 
5
- output = L42::Monad.functional_input(L42::Interfaces::TxSend, ARGV.first)
6
- output&.each do | line |
6
+ output =
7
+ L42::Monad
8
+ .functional_input(L42::Interfaces::TxSend, ARGV.first, use_params: ARGV.drop(1))
9
+ output&.each do |line|
7
10
  system(line)
8
11
  end
9
12
  # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ module L42
5
+ module Interfaces
6
+ module MapInp
7
+ extend self
8
+
9
+ def call(input, pattern)
10
+ pattern = pattern.gsub(Now, Time.now.to_i.to_s(16))
11
+ [
12
+ :stdout,
13
+ input.each_with_index.map(&_map(pattern))
14
+ ]
15
+ end
16
+
17
+ private
18
+
19
+ Count = %r{(?<!%)%c}
20
+ FormattedCount = %r{(?<!%)%f(\d+)}
21
+ Now = %r{(?<!%)%x}
22
+ Replacer = %r{(?<!%)%(?!%)}
23
+
24
+ def _map(pattern)
25
+ ->(record, idx) do
26
+ _transform_inp(pattern, record, idx)
27
+ end
28
+ 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
+ end
44
+ end
45
+ end
46
+ # 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/monad.rb CHANGED
@@ -6,8 +6,8 @@ module L42
6
6
 
7
7
  class ContractViolation < RuntimeError; end
8
8
 
9
- def interact(interactor)
10
- case interactor.($stdin.readlines(chomp: true))
9
+ def interact(interactor, *args, **kwds)
10
+ case interactor.($stdin.readlines(chomp: true), *args, **kwds)
11
11
  in [:stdout, output]
12
12
  $stdout.puts(output)
13
13
  in [:stderr, output]
@@ -30,8 +30,10 @@ module L42
30
30
  end
31
31
  end
32
32
 
33
- def functional_input(transformer, *args)
34
- case transformer.($stdin.readlines(chomp: true), *args)
33
+ def functional_input(transformer, *args, use_params: nil)
34
+ input =
35
+ use_params || $stdin.readlines(chomp: true)
36
+ case transformer.(input, *args)
35
37
  in [:stdout, output]
36
38
  output
37
39
  in [:stderr, output]
data/lib/l42/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module L42
4
4
  module Version
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.6'
6
6
  end
7
7
  end
8
8
  # 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.3
4
+ version: 0.1.6
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-08-25 00:00:00.000000000 Z
11
+ date: 2022-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lab42_rgxargs
@@ -30,6 +30,8 @@ description: |
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,15 @@ 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/pfx_by_now.rb
46
52
  - lib/l42/interfaces/to_random.rb
47
53
  - lib/l42/interfaces/tx_send.rb
48
54
  - lib/l42/interfaces/with_ts.rb