GPI 0.0.0
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 +7 -0
- data/lib/gpi.rb +55 -0
- data/lib/gpi/classes.rb +22 -0
- data/lib/gpi/clu.rb +105 -0
- data/lib/gpi/dir.rb +34 -0
- data/lib/gpi/file.rb +15 -0
- data/lib/gpi/hash.rb +20 -0
- data/lib/gpi/numeric.rb +27 -0
- data/lib/gpi/string.rb +14 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ae7c34822d7a2f93052ed91c050ff3c85a7842c9aeb14b8cf7e3f077a5be772b
|
4
|
+
data.tar.gz: ef36c64d88dacebcefcbb21d0f09c66360dc4b7546060b979a701a8d267de813
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f1075ca45930895d5bd23d858eb533669f0c991723f4c92a154545d942cb374cf6d1704badf309612ce1c89c7310a4220c8e1da3202371acd8a472d1a7f3b3a
|
7
|
+
data.tar.gz: 2145b4136d97a5cbc7f27beeaf7665bfd5f1fc5eb08a9f6cc4ad2e0c253f83bf64a54eb88c484adbbca1d27242268218867d181f68dff23163717e0b8eb6b52e
|
data/lib/gpi.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module GPI
|
2
|
+
|
3
|
+
@app_name = "GPI"
|
4
|
+
|
5
|
+
def self.gem_interface_test
|
6
|
+
GPI.print "gem integration successful"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.quit
|
10
|
+
GPI.print "aborted"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.app_name=(str)
|
15
|
+
@app_name = str
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.app_name
|
19
|
+
@app_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.print(str, o = nil)
|
23
|
+
if o.nil?
|
24
|
+
puts "#{@app_name} > " << str
|
25
|
+
else
|
26
|
+
if o
|
27
|
+
puts "#{@app_name} > " << str
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.extend(sym)
|
33
|
+
case sym
|
34
|
+
when :dir
|
35
|
+
Dir.class_eval { include DirExtend }
|
36
|
+
when :file
|
37
|
+
File.class_eval { include FileExtend }
|
38
|
+
when :hash
|
39
|
+
Hash.class_eval { include HashExtend }
|
40
|
+
when :numeric
|
41
|
+
Numeric.class_eval { include NumericExtend }
|
42
|
+
when :string
|
43
|
+
String.class_eval { include StringExtend }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
require 'gpi/classes.rb'
|
48
|
+
require 'gpi/clu.rb'
|
49
|
+
require 'gpi/dir.rb'
|
50
|
+
require 'gpi/file.rb'
|
51
|
+
require 'gpi/hash.rb'
|
52
|
+
require 'gpi/numeric.rb'
|
53
|
+
require 'gpi/string.rb'
|
54
|
+
|
55
|
+
end # END OF MODULE
|
data/lib/gpi/classes.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Command
|
2
|
+
attr_accessor :name, :pcount, :options
|
3
|
+
|
4
|
+
def initialize(name, pcount, options)
|
5
|
+
@name = name
|
6
|
+
@pcount = pcount
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Option
|
12
|
+
attr_accessor :name, :param
|
13
|
+
|
14
|
+
def initialize(name)
|
15
|
+
@name = name
|
16
|
+
@param = Array.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_param(str)
|
20
|
+
@param.push(str)
|
21
|
+
end
|
22
|
+
end
|
data/lib/gpi/clu.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
module GPI
|
2
|
+
|
3
|
+
module CLU # Command Line Utilities
|
4
|
+
|
5
|
+
#####################
|
6
|
+
# @command
|
7
|
+
# @commands
|
8
|
+
# @appcom | flag
|
9
|
+
|
10
|
+
def self.init
|
11
|
+
@appcom = false
|
12
|
+
@commands = Array.new
|
13
|
+
@parameters = Array.new
|
14
|
+
@options = Array.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.command
|
18
|
+
@command.name
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parameters
|
22
|
+
@parameters
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.options
|
26
|
+
@options
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.check_option(str)
|
30
|
+
@options.each do |o|
|
31
|
+
return true if o.name == str
|
32
|
+
end
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.process_args
|
37
|
+
@command = nil
|
38
|
+
# attempt to find command
|
39
|
+
if @appcom
|
40
|
+
@command = @commands[0]
|
41
|
+
else
|
42
|
+
if ARGV.length >= 1
|
43
|
+
@commands.each do |c|
|
44
|
+
@command = c if ARGV[0] == c.name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
i = 0
|
49
|
+
z = -1 # used to assign paramter to command or correct option
|
50
|
+
ARGV.each do |arg|
|
51
|
+
i += 1
|
52
|
+
next if (i == 1 && !@appcom) # skip if command
|
53
|
+
if arg[0] == '-' # option(s)
|
54
|
+
arg.each_char do |c|
|
55
|
+
next if c == '-'
|
56
|
+
if @command.options.include?(c)
|
57
|
+
@options.push(Option.new(c))
|
58
|
+
z = @options.size - 1
|
59
|
+
else
|
60
|
+
GPI.print "Invalid option for command #{@command.name}"
|
61
|
+
GPI.print "Legal options:"
|
62
|
+
@command.options.each_char do |c|
|
63
|
+
GPI.print "-#{c}"
|
64
|
+
end
|
65
|
+
GPI.quit
|
66
|
+
end
|
67
|
+
end
|
68
|
+
else # parameter
|
69
|
+
if z == -1 # command parameter
|
70
|
+
@parameters.push(arg)
|
71
|
+
else
|
72
|
+
@options[z].add_param(arg)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
require_command
|
77
|
+
unless @command.pcount.include?(@parameters.size)
|
78
|
+
GPI.print "Invalid number of parameters for command given"
|
79
|
+
GPI.quit
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.require_command
|
84
|
+
# exit when no command given
|
85
|
+
if @command.nil?
|
86
|
+
# no valid command, exit
|
87
|
+
GPI.print "Missing or Invalid Command."
|
88
|
+
GPI.print "Legal commands are:"
|
89
|
+
@commands.each { |c| GPI.print "- #{c.name}" }
|
90
|
+
GPI.quit
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.use_command(name, pcount, options) # if program has multiple commands
|
95
|
+
@commands.push(Command.new(name, pcount, options))
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.app_command(pcount, options) # if app only accepts parameters
|
99
|
+
@commands.push(Command.new(GPI.app_name, pcount, options))
|
100
|
+
@appcom = true
|
101
|
+
end
|
102
|
+
|
103
|
+
end # END OF MODULE
|
104
|
+
|
105
|
+
end # END OF MODULE
|
data/lib/gpi/dir.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module GPI
|
2
|
+
|
3
|
+
module DirExtend
|
4
|
+
|
5
|
+
def Dir.directories(dir)
|
6
|
+
Dir.entries(dir).select do |f|
|
7
|
+
File.directory?(File.join(dir,f)) && f != "." && f != ".."
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def Dir.files(dir)
|
12
|
+
Dir.entries(dir).select do |f|
|
13
|
+
!(File.directory?(File.join(dir,f)))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def Dir.filesr(dir, ar = Array.new)
|
18
|
+
Dir.entries(dir).each do |f|
|
19
|
+
if File.directory?(File.join(dir, f))
|
20
|
+
if f == "." || f == ".."
|
21
|
+
next
|
22
|
+
else
|
23
|
+
Dir.filesr(File.join(dir, f), ar)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
ar.push File.join(dir, f)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
ar
|
30
|
+
end
|
31
|
+
|
32
|
+
end # END OF MIXIN
|
33
|
+
|
34
|
+
end # END OF MODULE
|
data/lib/gpi/file.rb
ADDED
data/lib/gpi/hash.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module GPI
|
2
|
+
|
3
|
+
module HashExtend
|
4
|
+
|
5
|
+
def to_module(name)
|
6
|
+
h = self
|
7
|
+
m = eval("::#{name.capitalize} = Module.new")
|
8
|
+
m.class_eval {
|
9
|
+
instance_variable_set(:@hash, h)
|
10
|
+
h.each_key do |k|
|
11
|
+
define_singleton_method k do
|
12
|
+
@hash[k]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
end # END OF MIXIN
|
19
|
+
|
20
|
+
end # END OF NAMESPACE
|
data/lib/gpi/numeric.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module GPI
|
2
|
+
|
3
|
+
module NumericExtend
|
4
|
+
|
5
|
+
def mib_to_bytes
|
6
|
+
self.to_f * (1024 * 1024).to_f
|
7
|
+
end
|
8
|
+
|
9
|
+
def bytes_to_mib
|
10
|
+
self.to_f / (1024 * 1024).to_f
|
11
|
+
end
|
12
|
+
|
13
|
+
def mb_to_bytes
|
14
|
+
self.to_f * (1000 * 1000).to_f
|
15
|
+
end
|
16
|
+
|
17
|
+
def mb_to_mib
|
18
|
+
a = self.mb_to_bytes
|
19
|
+
b = self.mib_to_bytes
|
20
|
+
c = b - a
|
21
|
+
d = a - c
|
22
|
+
d.bytes_to_mib
|
23
|
+
end
|
24
|
+
|
25
|
+
end # END OF MIXIN
|
26
|
+
|
27
|
+
end # END OF NAMESPACE
|
data/lib/gpi/string.rb
ADDED
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: GPI
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tohya ryu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: lib for writing gems
|
14
|
+
email: ryu@tohya.net
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/gpi.rb
|
20
|
+
- lib/gpi/classes.rb
|
21
|
+
- lib/gpi/clu.rb
|
22
|
+
- lib/gpi/dir.rb
|
23
|
+
- lib/gpi/file.rb
|
24
|
+
- lib/gpi/hash.rb
|
25
|
+
- lib/gpi/numeric.rb
|
26
|
+
- lib/gpi/string.rb
|
27
|
+
homepage: https://github.com/tohya-ryu/GPI
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.7.6.2
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: basic method lib
|
51
|
+
test_files: []
|