xprint 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/version.rb +1 -1
- data/lib/xprint.rb +53 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f22ce4523589e6cbeb06e54a7a1977a75ec1756ab30f089732bcc8c3b45dff1
|
4
|
+
data.tar.gz: fb2846b5666efd1edcc52724f9abfbb1800d519c2a38677e7307fc819e935555
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b92e59c74c96172d0f8a30922588d0cfae72eb7eff4ad7c3ca0eaa97c6884b93a06866d70559fac46ce76818dfeb978e94f044b1a4ceccaffea7c9ecbb20304
|
7
|
+
data.tar.gz: 38a4585448847ffebc5c873dafa351f16a4ef082f2d41c121161b7d6e405f4b660d648197600f332549da5d835e346c5684a21f5365ac046c5e4c223b983cfbb
|
data/lib/version.rb
CHANGED
data/lib/xprint.rb
CHANGED
@@ -7,14 +7,23 @@ module XPrint
|
|
7
7
|
@tab = "\t"
|
8
8
|
@show_indexes = true
|
9
9
|
@full_proc_path = false
|
10
|
+
@braces = true
|
10
11
|
|
11
12
|
def self.set(**kwargs)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@
|
13
|
+
set_vars = {
|
14
|
+
tab: ->(data) { @tab = data },
|
15
|
+
show_indexes: ->(data) { @show_indexes = data },
|
16
|
+
full_proc_path: ->(data) { @full_proc_path = data },
|
17
|
+
braces: ->(data) { @braces = data }
|
18
|
+
}
|
19
|
+
|
20
|
+
kwargs.each do |keyword, arg|
|
21
|
+
if set_vars.key? keyword
|
22
|
+
set_vars[keyword].(arg)
|
23
|
+
end
|
17
24
|
end
|
25
|
+
|
26
|
+
return
|
18
27
|
end
|
19
28
|
|
20
29
|
def self.tab()
|
@@ -27,8 +36,33 @@ module XPrint
|
|
27
36
|
|
28
37
|
def self.xp(*args)
|
29
38
|
args.each do |arg|
|
30
|
-
|
39
|
+
xpanded_text = self.xpand(arg, tab: @tab)
|
40
|
+
|
41
|
+
unless @braces
|
42
|
+
xpanded_text = self.shift_indentation_down(xpanded_text).lstrip()
|
43
|
+
end
|
44
|
+
|
45
|
+
puts xpanded_text
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
private_class_method def self.shift_indentation_down(text)
|
51
|
+
# Only shift if no
|
52
|
+
return text if text.match?(/^\S/)
|
53
|
+
result = ''
|
54
|
+
|
55
|
+
text.each_line do |line|
|
56
|
+
result += (
|
57
|
+
if line.start_with? @tab
|
58
|
+
line[@tab.length..-1]
|
59
|
+
else
|
60
|
+
line
|
61
|
+
end
|
62
|
+
)
|
31
63
|
end
|
64
|
+
|
65
|
+
return result
|
32
66
|
end
|
33
67
|
|
34
68
|
def self.xpand(x, indent: '', tab: "\t")
|
@@ -52,8 +86,10 @@ module XPrint
|
|
52
86
|
|
53
87
|
return "<#{type} @ #{source} [Line #{line}]>"
|
54
88
|
# X is an Array, print list of all items.
|
89
|
+
elsif x.class == Class
|
90
|
+
return "<Class #{x}>"
|
55
91
|
elsif x.class == Array
|
56
|
-
result = "[\n"
|
92
|
+
result = "#{@braces ? '[' : ''}\n"
|
57
93
|
|
58
94
|
x.each_with_index do |item, index|
|
59
95
|
data = xpand(item, indent: _indent, tab: tab)
|
@@ -63,15 +99,15 @@ module XPrint
|
|
63
99
|
result += "#{data}"
|
64
100
|
|
65
101
|
unless index + 1 == x.length
|
66
|
-
result += ", \n"
|
102
|
+
result += "#{@braces ? ', ' : ''} \n"
|
67
103
|
end
|
68
104
|
end
|
69
105
|
|
70
|
-
result += "\n#{indent}]"
|
106
|
+
result += "\n#{indent}]" if @braces
|
71
107
|
return result
|
72
108
|
# X is a Hash, print all keys and values.
|
73
109
|
elsif x.class == Hash
|
74
|
-
result = "{\n"
|
110
|
+
result = "#{@braces ? '{' : ''}\n"
|
75
111
|
|
76
112
|
longest_key = (
|
77
113
|
x.keys.filter do |k, v|
|
@@ -105,12 +141,12 @@ module XPrint
|
|
105
141
|
end
|
106
142
|
end
|
107
143
|
|
108
|
-
result += "\n#{indent}}"
|
144
|
+
result += "\n#{indent}}" if @braces
|
109
145
|
|
110
146
|
return result
|
111
147
|
# X is a Structure; essentially a special case of X being an object.
|
112
148
|
elsif x.is_a? Struct
|
113
|
-
result = "Struct #{x.class}(\n"
|
149
|
+
result = "Struct #{x.class}#{@braces ? '(' : ''}\n"
|
114
150
|
longest_item = x.members.map { |m| m.to_s.length }.max()
|
115
151
|
|
116
152
|
x.each_pair do |name, value|
|
@@ -120,13 +156,15 @@ module XPrint
|
|
120
156
|
result += "#{_indent}#{attr_name} = #{attr_data}\n"
|
121
157
|
end
|
122
158
|
|
123
|
-
result += "#{indent})"
|
159
|
+
result += "#{indent})" if @braces
|
124
160
|
|
125
161
|
return result
|
126
162
|
# X is any arbitrary object; print all instance variables.
|
127
163
|
else
|
128
|
-
|
164
|
+
classname = x.class == Module ? "Module #{x}" : x.class
|
165
|
+
result = "#{classname}#{@braces ? '(' : ''}"
|
129
166
|
ivars = x.instance_variables
|
167
|
+
result += "\n" if ivars.length > 0
|
130
168
|
longest_var = ivars.map { |v| v.to_s.length }.max()
|
131
169
|
|
132
170
|
ivars.each_with_index do |var, index|
|
@@ -140,7 +178,7 @@ module XPrint
|
|
140
178
|
result += "#{_indent}#{attr_name} = #{attr_data}\n"
|
141
179
|
end
|
142
180
|
|
143
|
-
result += "#{indent})"
|
181
|
+
result += "#{ivars.length > 0 ? indent: ''})" if @braces
|
144
182
|
|
145
183
|
return result
|
146
184
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JCabr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Gem that allows for pretty printing data over multiple lines and with
|
14
14
|
indentation, and works with objects as well as basic data types.
|