helpema 3.1.210909 → 4.0.221210

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: 06db87416d69a4ed736c20927d8f9d3c379d7654cbd3e85f57e6e44a5571098e
4
- data.tar.gz: e0f8202e576a5ba7d7fb30ec1b045bc8da3bf1c696bf98874b30c032820e45a8
3
+ metadata.gz: a67c2f9a3a5481f978441ef416a1728d754002990dfb03237c949631836ead05
4
+ data.tar.gz: 54b942322fa0059c494a45d7ba8a63b2266ea83a2486cfa32beb0c27f95c1fd4
5
5
  SHA512:
6
- metadata.gz: 0e59e80e64f0c88ac0a0948ff773b9238f7334939231d70c70aec105217962cc4e3e68276b29013cb4e22eec57e392031b2f927c690d29d35999ca236860b1ee
7
- data.tar.gz: aaddb40d73e6d372d50ff61244232dbc998076806dcc3903fefd1c46647e3f739bfd9b0b0d6d29ab4b56c8bfb0411d2314bee2505ceae11c90ffeb717b2cf781
6
+ metadata.gz: a36106b836f299738037425d8087c51fbb977783d3b76ccfe18235ac07f2b0a5dfcdbaf8f1996fedf04793f88d2864ae04c05ba1edb158117797d7dee92d13f6
7
+ data.tar.gz: 10c6abdeb86321c0b64f8fd275dc25e12c9cd4d2ae2e82dfb864f9898f42c3633202b79afe88f962732e5be9b97638a4cc181c1ce2eb3860a3b2ae967fbbf645
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Helpema
2
2
 
3
- * [VERSION 3.1.210909](https://github.com/carlosjhr64/helpema/releases)
3
+ * [VERSION 4.0.221210](https://github.com/carlosjhr64/helpema/releases)
4
4
  * [github](https://github.com/carlosjhr64/helpema)
5
5
  * [rubygems](https://rubygems.org/gems/helpema)
6
6
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  Meant to be an eclectic collection of useful single functions and wrappers.
10
10
 
11
- Featured method: `requires "good ~>3.0", "bad ~>2.7", "ugly ~>1.8"`
11
+ Featured function: `Helpema.requires "good ~>3.0", "bad ~>2.7", "ugly ~>1.8"`
12
12
 
13
13
  ## INSTALL:
14
14
 
@@ -18,95 +18,132 @@ $ gem install helpema
18
18
 
19
19
  ## SYNOPSIS:
20
20
 
21
+ ### Helpema.requires
21
22
  ```ruby
22
23
  require 'helpema'
23
- include Helpema
24
- using Helpema
25
24
 
26
25
  ### requires ###
27
26
  # Ensure ruby's and helpema's version.
28
27
  # Returns the list of loaded gems.
29
28
  # For those quick little scripts one writes in one's bin
30
29
  # that annoyingly keep falling out of maintainance... right?
31
- requires'
30
+ Helpema.requires'
32
31
  ruby ~>3.0
33
- helpema ~>3.1
34
- base_convert ~>4.0
35
- entropia ~>0.1'
32
+ helpema ~>4.0
33
+ base_convert ~>6.0
34
+ entropia ~>1.0'
36
35
  #=> ["base_convert", "entropia"]
37
-
38
- ### String#satisfies? ###
39
- # Uses Gem::Requirement and Gem::Version to check version strings.
40
- '1.2.3'.satisfies? '~>1.1' #=> true
41
- '1.2.3'.satisfies? '~>1.3' #=> false
42
-
43
- ### run_command ###
44
- # Automates pipe creation to a system command.
45
- # See the code for all available features.
46
- run_command('date',{d: 'Dec 31, 2020'}) #=> "Thu Dec 31 12:00:00 AM PST 2020\n"
47
-
36
+ ```
37
+ ### Helpema::Refinements
38
+ ```ruby
39
+ using Helpema::Refinements
40
+ RUBY_VERSION.satisfies?('~>3.1') #=> true
41
+ '2.7.5'.satisfies?('~>3.1') #=> false
42
+ begin
43
+ requires 'ruby ~>9000'
44
+ rescue
45
+ msg = $!.message
46
+ end
47
+ msg #=> "ruby 3.1.2 not ~>9000"
48
+ ```
49
+ ### Helpema::Piper
50
+ ```ruby
51
+ include Helpema
52
+ # These will raise RuntimeError unless version matches:
53
+ Piper.validate_command('ruby', '^ruby 3.1.2p20', '--version')
54
+ Piper.validate_command('ssss-split', 'Version: 0\.[567]$', '-v')
55
+ # Piper.run_command(cmd, options={}, script:nil, usage=nil, synonyms:nil,
56
+ # mode:'r', exception:nil, forward_pass:nil **popt, &blk)
57
+ # Too many features to fully cover in a synopsis...
58
+ Piper.run_command('date',{d: 'Dec 31, 2020',I: true}) #=> "2020-12-31\n"
59
+ Piper.run_command('bash',script:'echo "Hello"',mode:'w+') #=> "Hello\n"
60
+ Piper.run_command('fish',script:'false',mode:'w',exception:false) #=> false
61
+ begin
62
+ Piper.run_command('fish',script:'false',mode:'w',exception:'Ooops!')
63
+ rescue
64
+ msg = $!.message
65
+ end
66
+ msg #=> "Ooops!"
67
+ ```
68
+ ### Helpema::Piper::Refinements
69
+ ```ruby
70
+ using Piper::Refinements
71
+ {d: 'Dec 31, 2020',I: true}.to_args #=> ["-d", "Dec 31, 2020", "-I"]
72
+ {'date=': '2022-12-10', wut: true}.to_args #=> ["--date=2022-12-10", "--wut"]
73
+ ```
74
+ ### extend Helpema::Piper
75
+ ```ruby
48
76
  ### define_command ###
49
- # Creates a method out of a system command.
50
- # See the code for all available features.
51
- define_command(:date, cmd: 'date', usage: {d: nil}, synonyms: {string: :d})
52
- date(string: 'Dec 31, 2020') #=> "Thu Dec 31 12:00:00 AM PST 2020\n"
53
-
54
- ### to_arg ###
55
- # A helper function to do system command calls.
56
- to_arg :q, true #=> "-q"
57
- to_arg :quiet, true #=> "--quiet"
58
- to_arg :verbose, false #=> nil
59
- to_arg :f, '/path-to/file' #=> ["-f", "/path-to/file"]
60
- to_arg :geo=, '10x20' #=> "--geo=10x20"
61
- to_arg :arg0, 'Hello World' #=> "Hello World"
62
-
63
- ### Hash#to_args ###
64
- { q: true,
65
- quiet: true,
66
- verbose: false,
67
- f: '/path-to/file',
68
- :geo= => '10x20',
69
- arg0: 'Hello World' }.to_args
70
- #=> ["-q", "--quiet", "-f", "/path-to/file", "--geo=10x20", "Hello World"]
71
-
72
- ### Array#classify ###
73
- # Groups items in Array by class.
74
- [1, 2.0, :Three, 'Four', /Five/, :Six, 'Seven'].classify
75
- #=> {Integer=>[1], Float=>[2.0], Symbol=>[:Three, :Six], String=>["Four", "Seven"], Regexp=>[/Five/]}
76
-
77
+ # Create a method out of a system command.
78
+ module System
79
+ extend Helpema::Piper
80
+ define_command(:date, cmd: 'date', usage: {d: nil, I: true}, synonyms: {string: :d})
81
+ extend self
82
+ end
83
+ System.date(string: 'Dec 31, 2020') #=> "2020-12-31\n"
84
+ ```
85
+ ### Helpema::Rubish
86
+ ```ruby
87
+ # Predefined Rubish:
88
+ Rubish.bash 'echo "Hello!"' #=> "Hello!\n"
89
+ Rubish.bash? 'which ruby' #=> true
90
+ Rubish.fish? 'false' #=> false
91
+ # Define you own Rubish shell call:
92
+ Rubish.shell('ruby', default:'puts RUBY_VERSION')
93
+ Rubish.ruby #=> "3.1.2\n"
94
+ Rubish.ruby('puts "Hello!"') #=> "Hello!\n"
95
+ # And define you own Rubish command call:
96
+ Rubish.command('which', usage:{arg0:nil})
97
+ def which(cmd) = Rubish.which(arg0:cmd)
98
+ which 'echo' # "/usr/bin/echo\n"
99
+ ```
100
+ ### Helpema::SSSS.split
101
+ ```ruby
77
102
  ### SSSS.split ####
78
103
  SSSS.split(secret: "Top Secret!", threshold: 2, shares: 3)
79
104
  #~> ^\["1-\h+", "2-\h+", "3-\h+"\]$
80
105
  # Note that the split has random outputs on the same inputs.
81
-
106
+ ```
107
+ ### SSS.combine
108
+ ```ruby
82
109
  #### SSSS.combine ###
83
110
  # Pregenerated splits combine to reproduce the secret.
84
111
  SSSS.combine(secrets: ["3-055562917c41e68c6ab2c8", "1-27bf3cbfe8d2c25c7e8928"],
85
112
  threshold: 2)
86
113
  #=> "Top Secret!"
87
-
114
+ ```
115
+ ### YouTubeDL.json
116
+ ```ruby
88
117
  ### YouTubeDL.json ###
89
118
  list = []
90
119
  url = 'https://www.youtube.com/watch?v=u4oK3ZSccZI'
91
- YouTubeDL.json(url){|json| list.push json}
120
+ Helpema::YouTubeDL.json(url){|json| list.push json}
92
121
  # The url was for just one video
93
122
  list.length #=> 1
94
123
  json = list[0]
95
124
  json['title'] #=> "Fortnite Easy Last Ten"
96
-
125
+ ```
126
+ ### YouTubeDL.mp3(url, output: '%(id)s.%(ext)s')
127
+ ### FFMPEG.hash(filename, digest: 'sha160')
128
+ ### ZBar.screen
129
+ ```ruby
97
130
  ### ZBar.screen ###
98
131
  # Reads qrcodes on screen.
99
- string_or_nil = ZBar.screen
100
-
132
+ string_or_nil = Helpema::ZBar.screen
133
+ ```
134
+ ### ZBar.cam
135
+ ```ruby
101
136
  ### ZBar.cam ###
102
137
  # Reads qrcodes from camera.
103
138
  # You may want to wrap this one in a Timeout block.
104
139
  # string = ZBar.cam
105
-
140
+ ```
141
+ ### GPG.encrypt and GPG.decrypt
142
+ ```ruby
106
143
  ### GPG Symmetric ###
107
144
  ## String to String
108
- encrypted = GPG.encrypt(passphrase: '<Secret>', string: '<Plain Text>')
109
- decrypted = GPG.decrypt(passphrase: '<Secret>', string: encrypted)
145
+ encrypted = Helpema::GPG.encrypt(passphrase: '<Secret>', string: '<Plain Text>')
146
+ decrypted = Helpema::GPG.decrypt(passphrase: '<Secret>', string: encrypted)
110
147
  #=> "<Plain Text>"
111
148
  ## File to File
112
149
  # Got a text file...
@@ -115,9 +152,9 @@ decrypted = GPG.decrypt(passphrase: '<Secret>', string: encrypted)
115
152
  File.exist?(_='tmp/text.enc') and File.unlink(_)
116
153
  File.exist?(_='tmp/text.dec') and File.unlink(_)
117
154
  # Encrypt text file...
118
- GPG.encrypt(passphrase: '<Secret>', input: 'tmp/text.txt', output: 'tmp/text.enc') #=> ""
155
+ Helpema::GPG.encrypt(passphrase: '<Secret>', input: 'tmp/text.txt', output: 'tmp/text.enc') #=> ""
119
156
  # Decrypt encrypted file...
120
- GPG.decrypt(passphrase: '<Secret>', input: 'tmp/text.enc', output: 'tmp/text.dec') #=> ""
157
+ Helpema::GPG.decrypt(passphrase: '<Secret>', input: 'tmp/text.enc', output: 'tmp/text.dec') #=> ""
121
158
  # Decrypted file should match...
122
159
  `md5sum tmp/text.dec` #~> ^d27b3111fdeb72f2862909c216214bc1
123
160
  ## IO to IO
@@ -125,25 +162,20 @@ require 'stringio'
125
162
  pio = StringIO.new '<Plain>'
126
163
  eio = StringIO.new ''
127
164
  dio = StringIO.new ''
128
- GPG.encrypt(passphrase: '<Secret>', ioin: pio, ioout: eio)
165
+ Helpema::GPG.encrypt(passphrase: '<Secret>', ioin: pio, ioout: eio)
129
166
  eio.rewind
130
- GPG.decrypt(passphrase: '<Secret>', ioin: eio, ioout: dio)
167
+ Helpema::GPG.decrypt(passphrase: '<Secret>', ioin: eio, ioout: dio)
131
168
  dio.string #=> "<Plain>"
132
169
  ```
133
-
134
170
  ## TROUBLESHOOTING:
135
171
 
136
- Command version mismatch
137
- : set `Helpema::WRAPPER.version = "your.version"` or just nil it.
138
-
139
- More documentation
140
- : see [sig/helpema.rb](sig/helpema.rbs) for the expected method signatures.
172
+ + Command version mismatch: set `Helpema::WRAPPER.version = "your.version"` or just nil it.
141
173
 
142
174
  ## LICENSE:
143
175
 
144
176
  (The MIT License)
145
177
 
146
- Copyright (c) 2021 CarlosJHR64
178
+ Copyright (c) 2022 CarlosJHR64
147
179
 
148
180
  Permission is hereby granted, free of charge, to any person obtaining
149
181
  a copy of this software and associated documentation files (the
@@ -0,0 +1,23 @@
1
+ module Helpema
2
+ module FFMPEG
3
+ extend Piper
4
+
5
+ FFMPEG.define_command(:_hash,
6
+ cmd: 'ffmpeg',
7
+ usage: {arg0: '-i',
8
+ arg1: nil,
9
+ arg2: '-f',
10
+ arg3: 'hash',
11
+ arg4: '-hash',
12
+ arg5: nil,
13
+ arg6: '-'},
14
+ synonyms: {filename: :arg1, digest: :arg5},
15
+ exception: 'ffmpeg failed',
16
+ err: '/dev/null')
17
+ def hash(filename, digest:'sha160')
18
+ FFMPEG._hash(filename:filename, digest:digest).strip.split('=').last
19
+ end
20
+
21
+ extend self
22
+ end
23
+ end
data/lib/helpema/gpg.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module Helpema
2
2
  module GPG
3
- extend Helpema
3
+ extend Piper
4
4
  class << self; attr_accessor :version; end
5
- GPG.version = '^gpg \\(GnuPG\\) 2\.[234]\.' # version as of this writing is 2.2.27
5
+ # version as of this writing is 2.2.27
6
+ GPG.version = '^gpg \\(GnuPG\\) 2\.[234]\.'
6
7
 
7
8
  GPG.define_command(:cryptor,
8
9
  cmd: 'gpg', version: GPG.version,
@@ -0,0 +1,104 @@
1
+ module Helpema
2
+ module Piper
3
+ module Refinements
4
+ refine ::Hash do
5
+ def to_args(usage:nil, synonyms:nil)
6
+ # create separate args from self with the translated synonyms
7
+ args = self.transform_keys(synonyms.to_h)
8
+ # pad usage's defaults to args
9
+ usage&.each{|key,default| args[key]=default unless args.has_key? key}
10
+ # order might be important so enforce usage
11
+ args = usage&.map{|k,v|[k,args[k]]} || args.to_a
12
+ # convert key,value tuples to final list of args
13
+ args.map!(&:to_arg)
14
+ # get rid of nil
15
+ args.compact!
16
+ # ...and finally flatten!
17
+ args.flatten!
18
+ return args
19
+ end
20
+ end
21
+ refine ::Symbol do
22
+ def to_flag
23
+ return nil if self[-1].match?(/\d/) # like :arg0
24
+ (self.length > 1)? "--#{self}": "-#{self}" # like --verbose or -V
25
+ end
26
+ end
27
+ refine ::Array do
28
+ def to_arg
29
+ Piper.to_arg(*self)
30
+ end
31
+ end
32
+ end
33
+
34
+ def Piper.validate_command(cmd, version, flag='--version')
35
+ raise "`#{cmd} #{flag}` !~ #{version}" unless
36
+ `#{cmd} #{flag}`.strip.match?(version)
37
+ end
38
+
39
+ # Note: popt is IO.popen's options(think of it as "pipe's options").
40
+ def define_command(name,
41
+ cmd:name.to_s.chomp('?').chomp('!'),
42
+ version:nil, v:nil,
43
+ usage:nil, synonyms:nil,
44
+ mode:'r', exception:nil, default:nil,
45
+ **popt, &forward_pass)
46
+ raise "bad name or cmd" unless name=~/^\w+[?!]?$/ and cmd=~/^[\w.\-]+$/
47
+ Piper.validate_command(cmd, version) if version
48
+ Piper.validate_command(cmd, v, '-v') if v
49
+ define_method(name) do |script=default, **options, &blk|
50
+ if mode[0]=='w'
51
+ raise 'need script to write' unless script or blk or forward_pass
52
+ else
53
+ raise 'cannot write script' if script
54
+ end
55
+ Piper.run_command(cmd, options, script:script,
56
+ usage:usage, synonyms:synonyms, mode:mode,
57
+ exception:exception, forward_pass:forward_pass, **popt, &blk)
58
+ end
59
+ end
60
+
61
+ using Refinements
62
+
63
+ def Piper.to_arg(key,value)
64
+ # keep only keys with value(no false or nil)
65
+ return nil unless value
66
+ # assume nil0/--long/-short
67
+ key = key.to_flag
68
+ if key
69
+ return key if value==true # a flag
70
+ return "#{key}#{value}" if key[-1]=='=' # joined key=value
71
+ return [key,value.to_s]
72
+ end
73
+ # It's a Nth arg, like arg0...
74
+ return value.to_s
75
+ end
76
+
77
+ # Assume caller knows what it's doing(no dummy proofing here)
78
+ def Piper.run_command(cmd, options={}, script:nil,
79
+ usage:nil, synonyms:nil, mode:'r',
80
+ exception:nil, forward_pass:nil, **popt, &blk)
81
+ args,ret = options.to_args(usage:usage,synonyms:synonyms),nil
82
+ $stderr.puts "#{cmd} #{args.join(' ')}" if $DEBUG
83
+ IO.popen([cmd, *args], mode, **popt) do |pipe|
84
+ pipe.write script if script
85
+ if forward_pass
86
+ ret = forward_pass.call(pipe, options, blk)
87
+ elsif blk
88
+ ret = blk.call(pipe, options)
89
+ elsif mode=='r'
90
+ ret = pipe.read
91
+ elsif mode=='w+'
92
+ pipe.close_write
93
+ ret = pipe.read
94
+ end
95
+ end
96
+ # False exception instead of nil or "an error message"
97
+ # flags the expected behavior as defined:
98
+ success = ($?.exitstatus==0)
99
+ raise(exception) if exception and not success
100
+ return success if exception==false
101
+ return ret
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,40 @@
1
+ module Helpema
2
+ module Rubish
3
+ extend Piper
4
+ def Rubish.shell(name,
5
+ cmd:name.to_s.chomp('?').chomp('!'),
6
+ version:nil, v:nil,
7
+ usage:nil, synonyms:nil,
8
+ exception:nil, default:nil)
9
+ if name[-1]=='?'
10
+ mode = 'w'
11
+ exception = false unless exception
12
+ else
13
+ mode = 'w+'
14
+ end
15
+ Rubish.define_command(name.to_sym,
16
+ cmd:cmd,
17
+ version:version, v:v,
18
+ usage:usage, synonyms:synonyms,
19
+ mode:mode, exception:exception,
20
+ default:default) # default script
21
+ end
22
+ Rubish.shell :fish
23
+ Rubish.shell :fish?
24
+ Rubish.shell :bash
25
+ Rubish.shell :bash?
26
+ def Rubish.command(name,
27
+ cmd:name.to_s.chomp('?').chomp('!'),
28
+ version:nil, v:nil,
29
+ usage:nil, synonyms:nil, exception:nil)
30
+ mode = 'r'
31
+ exception = false if name[-1]=='?' and not exception
32
+ Rubish.define_command(name.to_sym,
33
+ cmd:cmd,
34
+ version:version, v:v,
35
+ usage:usage, synonyms:synonyms,
36
+ mode:mode, exception:exception)
37
+ end
38
+ extend self
39
+ end
40
+ end
data/lib/helpema/ssss.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  module Helpema
2
2
  module SSSS
3
- extend Helpema
3
+ extend Piper
4
4
  class << self; attr_accessor :version; end
5
5
  SSSS.version = 'Version: 0\.[567]\b' # version as of this writing is 0.5
6
6
 
7
+ # To enforce a method signature, I wrap a `public` method around a
8
+ # `_private` `define_command` method. A `define_command` method looks like
9
+ # `_private(script=default,**options,&blk)`
10
+
7
11
  SSSS.define_command(:_split,
8
12
  cmd: 'ssss-split', v: SSSS.version,
9
13
  usage: {Q:true,t:2,n:3,w:nil,s:nil,x:false},
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module Helpema
4
4
  module YouTubeDL
5
- extend Helpema
5
+ extend Piper
6
6
  class << self; attr_accessor :version; end
7
7
  YouTubeDL.version = '^202\d\.[01]\d\.[0123]\d$'
8
8
 
@@ -21,6 +21,23 @@ module Helpema
21
21
  end
22
22
  def json(url, &blk) = YouTubeDL._json(url:url, &blk)
23
23
 
24
+ YouTubeDL.define_command(:_mp3,
25
+ cmd: 'youtube-dl', version: YouTubeDL.version,
26
+ usage: { output: nil,
27
+ format: true,
28
+ arg0: 'bestaudio',
29
+ 'extract-audio': true,
30
+ 'audio-format': true,
31
+ arg1: 'mp3',
32
+ 'audio-quality': true,
33
+ arg2: 0,
34
+ arg3: nil },
35
+ synonyms: {url: :arg3},
36
+ err: '/dev/null')
37
+
38
+ def mp3(url, output:'%(id)s.%(ext)s') =
39
+ YouTubeDL._mp3(url:url, output:output)
40
+
24
41
  extend self
25
42
  end
26
43
  end
data/lib/helpema/zbar.rb CHANGED
@@ -2,10 +2,10 @@ require 'tmpdir'
2
2
 
3
3
  module Helpema
4
4
  module ZBar
5
- extend Helpema
5
+ extend Piper
6
6
  class << self; attr_accessor :version, :screenshot; end
7
7
  ZBar.version = '^0\.2[345]\b' # version as of this writing is 0.23
8
- ZBar.screenshot = ['gnome-screenshot', '-f']
8
+ ZBar.screenshot = ['scrot']
9
9
 
10
10
  def snapshot(filename)
11
11
  system(*ZBar.screenshot, filename)
data/lib/helpema.rb CHANGED
@@ -1,12 +1,56 @@
1
1
  module Helpema
2
- VERSION = '3.1.210909'
3
-
4
- require_relative 'helpema/helpema'
2
+ VERSION = '4.0.221210'
5
3
 
4
+ autoload :Piper, 'helpema/piper.rb'
5
+ autoload :Rubish, 'helpema/rubish.rb'
6
6
  autoload :SSSS, 'helpema/ssss.rb'
7
7
  autoload :YouTubeDL, 'helpema/youtubedl.rb'
8
8
  autoload :ZBar, 'helpema/zbar.rb'
9
9
  autoload :GPG, 'helpema/gpg.rb'
10
+ autoload :FFMPEG, 'helpema/ffmpeg.rb'
11
+
12
+ module Refinements
13
+ refine ::String do
14
+ def satisfies?(*reqs)
15
+ Gem::Requirement.new(*reqs).satisfied_by? Gem::Version.new(self)
16
+ end
17
+ end
18
+
19
+ refine ::Kernel do
20
+ def requires(*list)
21
+ loaded = []
22
+ list.each do |gems|
23
+ gems.lines.each do |gemname_reqs|
24
+ gemname, *reqs = gemname_reqs.split
25
+ next unless gemname
26
+ unless reqs.empty?
27
+ case gemname
28
+ when 'helpema'
29
+ unless VERSION.satisfies?(*reqs)
30
+ raise "helpema #{VERSION} not #{reqs.join(', ')}"
31
+ end
32
+ next
33
+ when 'ruby'
34
+ unless RUBY_VERSION.satisfies?(*reqs)
35
+ raise "ruby #{RUBY_VERSION} not #{reqs.join(', ')}"
36
+ end
37
+ next
38
+ else
39
+ gem gemname, *reqs
40
+ end
41
+ end
42
+ require gemname and loaded.push gemname
43
+ end
44
+ end
45
+ return loaded
46
+ end
47
+ end
48
+ end
49
+
50
+ using Refinements
51
+ def Helpema.requires(*list)
52
+ Kernel.requires(*list)
53
+ end
10
54
  end
11
55
 
12
56
  # Requires:
@@ -16,5 +60,5 @@ end
16
60
  #`ssss-combine`
17
61
  #`zbarcam`
18
62
  #`zbarimg`
19
- #`gnome-screenshot`
63
+ #`scrot`
20
64
  #`gpg`
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helpema
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.210909
4
+ version: 4.0.221210
5
5
  platform: ruby
6
6
  authors:
7
7
  - CarlosJHR64
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-09 00:00:00.000000000 Z
11
+ date: 2022-12-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Meant to be an eclectic collection of useful single functions and wrappers.
15
15
 
16
- Featured method: `requires "good ~>3.0", "bad ~>2.7", "ugly ~>1.8"`
16
+ Featured function: `Helpema.requires "good ~>3.0", "bad ~>2.7", "ugly ~>1.8"`
17
17
  email: carlosjhr64@gmail.com
18
18
  executables: []
19
19
  extensions: []
@@ -21,8 +21,10 @@ extra_rdoc_files: []
21
21
  files:
22
22
  - README.md
23
23
  - lib/helpema.rb
24
+ - lib/helpema/ffmpeg.rb
24
25
  - lib/helpema/gpg.rb
25
- - lib/helpema/helpema.rb
26
+ - lib/helpema/piper.rb
27
+ - lib/helpema/rubish.rb
26
28
  - lib/helpema/ssss.rb
27
29
  - lib/helpema/youtubedl.rb
28
30
  - lib/helpema/zbar.rb
@@ -30,7 +32,7 @@ homepage: https://github.com/carlosjhr64/helpema
30
32
  licenses:
31
33
  - MIT
32
34
  metadata: {}
33
- post_install_message:
35
+ post_install_message:
34
36
  rdoc_options: []
35
37
  require_paths:
36
38
  - lib
@@ -45,16 +47,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
47
  - !ruby/object:Gem::Version
46
48
  version: '0'
47
49
  requirements:
48
- - 'ruby: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]'
50
+ - 'ruby: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [aarch64-linux]'
49
51
  - 'youtube-dl: 2021.06.06'
50
52
  - 'ssss-split: 0.5'
51
53
  - 'ssss-combine: 0.5'
52
- - 'zbarcam: 0.23'
53
- - 'zbarimg: 0.23'
54
- - 'gnome-screenshot: gnome-screenshot 40.0'
54
+ - 'zbarcam: 0.23.90'
55
+ - 'zbarimg: 0.23.90'
56
+ - 'scrot: scrot version 1.5'
55
57
  - 'gpg: gpg (GnuPG) 2.2.27'
56
- rubygems_version: 3.2.22
57
- signing_key:
58
+ rubygems_version: 3.3.7
59
+ signing_key:
58
60
  specification_version: 4
59
61
  summary: Meant to be an eclectic collection of useful single functions and wrappers.
60
62
  test_files: []
@@ -1,118 +0,0 @@
1
- module Helpema
2
- refine ::String do
3
- def satisfies?(*reqs)
4
- Gem::Requirement.new(*reqs).satisfied_by? Gem::Version.new(self)
5
- end
6
- end
7
- refine ::Hash do
8
- def to_args(usage:nil, synonyms:nil)
9
- # create separate args from self with the translated synonyms
10
- args = self.transform_keys(synonyms.to_h)
11
- # pad usage's defaults to args
12
- usage&.each{|key,default| args[key]=default unless args.has_key? key}
13
- # order might be important so enforce usage
14
- args = usage&.map{|k,v|[k,args[k]]} || args.to_a
15
- # convert key,value tuples to final list of args
16
- args.map!(&:to_arg)
17
- # get rid of nil
18
- args.compact!
19
- # ...and finally flatten!
20
- args.flatten!
21
- return args
22
- end
23
- end
24
- refine ::Array do
25
- def classify(hash: Hash.new{|h,k|h[k]=[]})
26
- self.each{|v| hash[v.class] << v}
27
- return hash
28
- end
29
- def to_arg
30
- Helpema.to_arg(*self)
31
- end
32
- end
33
- refine ::Symbol do
34
- def to_flag
35
- return nil if self[-1].match?(/\d/) # like :arg0
36
- (self.length > 1)? "--#{self}": "-#{self}" # like --verbose or -V
37
- end
38
- end
39
- using Helpema
40
-
41
- def to_arg(key,value)
42
- # keep only keys with value(no false or nil)
43
- return nil unless value
44
- # assume nil0/--long/-short
45
- key = key.to_flag
46
- if key
47
- return key if value==true # a flag
48
- return "#{key}#{value}" if key[-1]=='=' # joined key=value
49
- return [key,value.to_s]
50
- end
51
- # It's a Nth arg, like arg0...
52
- return value.to_s
53
- end
54
-
55
- def run_command(cmd, options={},
56
- usage:nil, synonyms:nil, mode:'r',
57
- exception:nil, forward_pass:nil, **popt, &blk)
58
- args,ret = options.to_args(usage:usage,synonyms:synonyms),nil
59
- $stderr.puts "#{cmd} #{args.join(' ')}" if $DEBUG
60
- IO.popen([cmd, *args], mode, **popt) do |pipe|
61
- ret = forward_pass ? forward_pass.call(pipe, options, blk) :
62
- blk ? blk.call(pipe) :
63
- pipe.read
64
- end
65
- (exception.nil? or $?.exitstatus==0)? ret : raise(exception)
66
- end
67
-
68
- def define_command(name,
69
- cmd: name.to_s, version: nil, v: nil,
70
- usage: nil, synonyms: nil,
71
- mode: 'r',exception: nil,
72
- **popt, &forward_pass)
73
-
74
- # which version? --version or -v
75
- if version and not `#{cmd} --version`.strip.match?(version)
76
- raise "`#{cmd} --version` !~ #{version}"
77
- end
78
- if v and not `#{cmd} -v`.strip.match?(v)
79
- raise "`#{cmd} -v` !~ #{v}"
80
- end
81
-
82
- define_method(name) do |**options, &blk|
83
- run_command(cmd, options,
84
- usage:usage, synonyms:synonyms, mode:mode,
85
- exception:exception, forward_pass:forward_pass, **popt, &blk)
86
- end
87
- end
88
-
89
- def requires(*list)
90
- loaded = []
91
- list.each do |gems|
92
- gems.lines.each do |gemname_reqs|
93
- gemname, *reqs = gemname_reqs.split
94
- next unless gemname
95
- unless reqs.empty?
96
- case gemname
97
- when 'helpema'
98
- unless VERSION.satisfies?(*reqs)
99
- raise "helpema #{VERSION} not #{reqs.join(', ')}"
100
- end
101
- next
102
- when 'ruby'
103
- unless RUBY_VERSION.satisfies?(*reqs)
104
- raise "ruby #{RUBY_VERSION} not #{reqs.join(', ')}"
105
- end
106
- next
107
- else
108
- gem gemname, *reqs
109
- end
110
- end
111
- require gemname and loaded.push gemname
112
- end
113
- end
114
- return loaded
115
- end
116
-
117
- extend self
118
- end