helpema 3.2.210924 → 4.0.221210

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 958027b0a2546243bae724c0a543197d7632385c0f9049d8e59ed53349b18f4d
4
- data.tar.gz: d57d402890e736b580fc052c66308df90a6e29202d467cd4e26714ad11b64331
3
+ metadata.gz: a67c2f9a3a5481f978441ef416a1728d754002990dfb03237c949631836ead05
4
+ data.tar.gz: 54b942322fa0059c494a45d7ba8a63b2266ea83a2486cfa32beb0c27f95c1fd4
5
5
  SHA512:
6
- metadata.gz: dd576603c81835d9610eac6d15487d25d82491eec8de717fcfbe6a16c51c865968d8ac259dddc45e02f2148f7653c6fa5b9ed5be55eb05c878b184df3bc5cdec
7
- data.tar.gz: 65f36c77c56ded75225ecd35fe6f6f4bb3581aeff1c3ce1de855f423e65de78e3e69d1131a63e7b18760b1224f27eda14a33c0a41e40e55bef67d8c0cb89b488
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.2.210924](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,76 +18,86 @@ $ gem install helpema
18
18
 
19
19
  ## SYNOPSIS:
20
20
 
21
- ### requires
21
+ ### Helpema.requires
22
22
  ```ruby
23
23
  require 'helpema'
24
- include Helpema
25
- using Helpema
26
24
 
27
25
  ### requires ###
28
26
  # Ensure ruby's and helpema's version.
29
27
  # Returns the list of loaded gems.
30
28
  # For those quick little scripts one writes in one's bin
31
29
  # that annoyingly keep falling out of maintainance... right?
32
- requires'
30
+ Helpema.requires'
33
31
  ruby ~>3.0
34
- helpema ~>3.1
35
- base_convert ~>4.0
36
- entropia ~>0.1'
32
+ helpema ~>4.0
33
+ base_convert ~>6.0
34
+ entropia ~>1.0'
37
35
  #=> ["base_convert", "entropia"]
38
36
  ```
39
- ### String#satisfies?
40
- ```ruby
41
- ### String#satisfies? ###
42
- # Uses Gem::Requirement and Gem::Version to check version strings.
43
- '1.2.3'.satisfies? '~>1.1' #=> true
44
- '1.2.3'.satisfies? '~>1.3' #=> false
45
- ```
46
- ### run_command
37
+ ### Helpema::Refinements
47
38
  ```ruby
48
- ### run_command ###
49
- # Automates pipe creation to a system command.
50
- # See the code for all available features.
51
- run_command('date',{d: 'Dec 31, 2020'}) #=> "Thu Dec 31 12:00:00 AM PST 2020\n"
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"
52
48
  ```
53
- ### define_command
49
+ ### Helpema::Piper
54
50
  ```ruby
55
- ### define_command ###
56
- # Creates a method out of a system command.
57
- # See the code for all available features.
58
- define_command(:date, cmd: 'date', usage: {d: nil}, synonyms: {string: :d})
59
- date(string: 'Dec 31, 2020') #=> "Thu Dec 31 12:00:00 AM PST 2020\n"
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!"
60
67
  ```
61
- ### to_arg
68
+ ### Helpema::Piper::Refinements
62
69
  ```ruby
63
- ### to_arg ###
64
- # A helper function to do system command calls.
65
- to_arg :q, true #=> "-q"
66
- to_arg :quiet, true #=> "--quiet"
67
- to_arg :verbose, false #=> nil
68
- to_arg :f, '/path-to/file' #=> ["-f", "/path-to/file"]
69
- to_arg :geo=, '10x20' #=> "--geo=10x20"
70
- to_arg :arg0, 'Hello World' #=> "Hello World"
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"]
71
73
  ```
72
- ### Hash#to_args
74
+ ### extend Helpema::Piper
73
75
  ```ruby
74
- ### Hash#to_args ###
75
- { q: true,
76
- quiet: true,
77
- verbose: false,
78
- f: '/path-to/file',
79
- :geo= => '10x20',
80
- arg0: 'Hello World' }.to_args
81
- #=> ["-q", "--quiet", "-f", "/path-to/file", "--geo=10x20", "Hello World"]
76
+ ### define_command ###
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"
82
84
  ```
83
- ### Array#classify
85
+ ### Helpema::Rubish
84
86
  ```ruby
85
- ### Array#classify ###
86
- # Groups items in Array by class.
87
- [1, 2.0, :Three, 'Four', /Five/, :Six, 'Seven'].classify
88
- #=> {Integer=>[1], Float=>[2.0], Symbol=>[:Three, :Six], String=>["Four", "Seven"], Regexp=>[/Five/]}
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"
89
99
  ```
90
- ### SSSS.split
100
+ ### Helpema::SSSS.split
91
101
  ```ruby
92
102
  ### SSSS.split ####
93
103
  SSSS.split(secret: "Top Secret!", threshold: 2, shares: 3)
@@ -107,7 +117,7 @@ SSSS.combine(secrets: ["3-055562917c41e68c6ab2c8", "1-27bf3cbfe8d2c25c7e8928"],
107
117
  ### YouTubeDL.json ###
108
118
  list = []
109
119
  url = 'https://www.youtube.com/watch?v=u4oK3ZSccZI'
110
- YouTubeDL.json(url){|json| list.push json}
120
+ Helpema::YouTubeDL.json(url){|json| list.push json}
111
121
  # The url was for just one video
112
122
  list.length #=> 1
113
123
  json = list[0]
@@ -119,7 +129,7 @@ json['title'] #=> "Fortnite Easy Last Ten"
119
129
  ```ruby
120
130
  ### ZBar.screen ###
121
131
  # Reads qrcodes on screen.
122
- string_or_nil = ZBar.screen
132
+ string_or_nil = Helpema::ZBar.screen
123
133
  ```
124
134
  ### ZBar.cam
125
135
  ```ruby
@@ -132,8 +142,8 @@ string_or_nil = ZBar.screen
132
142
  ```ruby
133
143
  ### GPG Symmetric ###
134
144
  ## String to String
135
- encrypted = GPG.encrypt(passphrase: '<Secret>', string: '<Plain Text>')
136
- 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)
137
147
  #=> "<Plain Text>"
138
148
  ## File to File
139
149
  # Got a text file...
@@ -142,9 +152,9 @@ decrypted = GPG.decrypt(passphrase: '<Secret>', string: encrypted)
142
152
  File.exist?(_='tmp/text.enc') and File.unlink(_)
143
153
  File.exist?(_='tmp/text.dec') and File.unlink(_)
144
154
  # Encrypt text file...
145
- 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') #=> ""
146
156
  # Decrypt encrypted file...
147
- 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') #=> ""
148
158
  # Decrypted file should match...
149
159
  `md5sum tmp/text.dec` #~> ^d27b3111fdeb72f2862909c216214bc1
150
160
  ## IO to IO
@@ -152,25 +162,20 @@ require 'stringio'
152
162
  pio = StringIO.new '<Plain>'
153
163
  eio = StringIO.new ''
154
164
  dio = StringIO.new ''
155
- GPG.encrypt(passphrase: '<Secret>', ioin: pio, ioout: eio)
165
+ Helpema::GPG.encrypt(passphrase: '<Secret>', ioin: pio, ioout: eio)
156
166
  eio.rewind
157
- GPG.decrypt(passphrase: '<Secret>', ioin: eio, ioout: dio)
167
+ Helpema::GPG.decrypt(passphrase: '<Secret>', ioin: eio, ioout: dio)
158
168
  dio.string #=> "<Plain>"
159
169
  ```
160
-
161
170
  ## TROUBLESHOOTING:
162
171
 
163
- Command version mismatch
164
- : set `Helpema::WRAPPER.version = "your.version"` or just nil it.
165
-
166
- More documentation
167
- : 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.
168
173
 
169
174
  ## LICENSE:
170
175
 
171
176
  (The MIT License)
172
177
 
173
- Copyright (c) 2021 CarlosJHR64
178
+ Copyright (c) 2022 CarlosJHR64
174
179
 
175
180
  Permission is hereby granted, free of charge, to any person obtaining
176
181
  a copy of this software and associated documentation files (the
@@ -1,6 +1,6 @@
1
1
  module Helpema
2
2
  module FFMPEG
3
- extend Helpema
3
+ extend Piper
4
4
 
5
5
  FFMPEG.define_command(:_hash,
6
6
  cmd: 'ffmpeg',
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
 
@@ -24,13 +24,19 @@ module Helpema
24
24
  YouTubeDL.define_command(:_mp3,
25
25
  cmd: 'youtube-dl', version: YouTubeDL.version,
26
26
  usage: { output: nil,
27
+ format: true,
28
+ arg0: 'bestaudio',
27
29
  'extract-audio': true,
28
30
  'audio-format': true,
29
- arg0: 'mp3',
30
- arg1: nil },
31
- synonyms: {url: :arg1},
31
+ arg1: 'mp3',
32
+ 'audio-quality': true,
33
+ arg2: 0,
34
+ arg3: nil },
35
+ synonyms: {url: :arg3},
32
36
  err: '/dev/null')
33
- def mp3(url, output:'%(id)s.%(ext)s') = YouTubeDL._mp3(url:url, output:output)
37
+
38
+ def mp3(url, output:'%(id)s.%(ext)s') =
39
+ YouTubeDL._mp3(url:url, output:output)
34
40
 
35
41
  extend self
36
42
  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,13 +1,56 @@
1
1
  module Helpema
2
- VERSION = '3.2.210924'
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
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
11
54
  end
12
55
 
13
56
  # Requires:
@@ -17,5 +60,5 @@ end
17
60
  #`ssss-combine`
18
61
  #`zbarcam`
19
62
  #`zbarimg`
20
- #`gnome-screenshot`
63
+ #`scrot`
21
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.2.210924
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-24 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: []
@@ -23,7 +23,8 @@ files:
23
23
  - lib/helpema.rb
24
24
  - lib/helpema/ffmpeg.rb
25
25
  - lib/helpema/gpg.rb
26
- - lib/helpema/helpema.rb
26
+ - lib/helpema/piper.rb
27
+ - lib/helpema/rubish.rb
27
28
  - lib/helpema/ssss.rb
28
29
  - lib/helpema/youtubedl.rb
29
30
  - lib/helpema/zbar.rb
@@ -31,7 +32,7 @@ homepage: https://github.com/carlosjhr64/helpema
31
32
  licenses:
32
33
  - MIT
33
34
  metadata: {}
34
- post_install_message:
35
+ post_install_message:
35
36
  rdoc_options: []
36
37
  require_paths:
37
38
  - lib
@@ -46,16 +47,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
47
  - !ruby/object:Gem::Version
47
48
  version: '0'
48
49
  requirements:
49
- - '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]'
50
51
  - 'youtube-dl: 2021.06.06'
51
52
  - 'ssss-split: 0.5'
52
53
  - 'ssss-combine: 0.5'
53
- - 'zbarcam: 0.23'
54
- - 'zbarimg: 0.23'
55
- - 'gnome-screenshot: gnome-screenshot 40.0'
54
+ - 'zbarcam: 0.23.90'
55
+ - 'zbarimg: 0.23.90'
56
+ - 'scrot: scrot version 1.5'
56
57
  - 'gpg: gpg (GnuPG) 2.2.27'
57
- rubygems_version: 3.2.22
58
- signing_key:
58
+ rubygems_version: 3.3.7
59
+ signing_key:
59
60
  specification_version: 4
60
61
  summary: Meant to be an eclectic collection of useful single functions and wrappers.
61
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