logue 1.0.4 → 1.0.5
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 +4 -4
- data/lib/logue/format.rb +21 -18
- data/lib/logue.rb +1 -1
- data/test/logue/format_test.rb +41 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 385cb8613ee04140fab6eacde15fa7ed4cb67ba1
|
4
|
+
data.tar.gz: e1e1649d69e92e3440dd02e43605debf063c72be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c8ba5bd3f9f039a49eba59cb4d41cb929adfa6aa886d93044039abc8824bc03d73e4be0cbc053432dfe915d867ce19eebbc8474bc0dc11aa61984984450c853
|
7
|
+
data.tar.gz: 07d5016f53177fe85a744bc6c588d10da300856bdc43db0d2c1183a41ee01fa0b7a058e25a5fbcddace3565d948aff3c14fe0c55f6247e5d728dde429e3633d4
|
data/lib/logue/format.rb
CHANGED
@@ -11,30 +11,33 @@ module Logue
|
|
11
11
|
def trim_right str, maxlen
|
12
12
|
mxln = maxlen.abs
|
13
13
|
|
14
|
-
# magic number 3 for the ellipses ...
|
15
|
-
|
16
14
|
if str.length > mxln
|
17
|
-
|
18
|
-
newstr = "..."
|
19
|
-
path.reverse.each do |element|
|
20
|
-
if newstr.length + element.length > mxln
|
21
|
-
while newstr.length < mxln
|
22
|
-
newstr.insert 0, " "
|
23
|
-
end
|
24
|
-
return newstr
|
25
|
-
else
|
26
|
-
if newstr.length > 3
|
27
|
-
newstr.insert 3, "/"
|
28
|
-
end
|
29
|
-
newstr.insert 3, element
|
30
|
-
end
|
31
|
-
end
|
32
|
-
newstr
|
15
|
+
trim_path_right str, maxlen
|
33
16
|
else
|
34
17
|
str
|
35
18
|
end
|
36
19
|
end
|
37
20
|
|
21
|
+
def trim_path_right path, maxlen
|
22
|
+
mxln = maxlen.abs
|
23
|
+
|
24
|
+
comps = path.split "/"
|
25
|
+
str = comps.pop
|
26
|
+
comps.reverse.each do |comp|
|
27
|
+
newstr = comp + "/" + str
|
28
|
+
if newstr.length + 4 <= mxln
|
29
|
+
str = newstr
|
30
|
+
else
|
31
|
+
newstr = "..." + "/" + str
|
32
|
+
if newstr.length <= mxln
|
33
|
+
str = newstr
|
34
|
+
end
|
35
|
+
break
|
36
|
+
end
|
37
|
+
end
|
38
|
+
str
|
39
|
+
end
|
40
|
+
|
38
41
|
def print_formatted file, line, func, msg, lvl, &blk
|
39
42
|
if trim
|
40
43
|
file = trim_right file, @file_width
|
data/lib/logue.rb
CHANGED
data/test/logue/format_test.rb
CHANGED
@@ -11,6 +11,8 @@ module Logue
|
|
11
11
|
class FormatTestCase < Test::Unit::TestCase
|
12
12
|
include Logue::Loggable
|
13
13
|
|
14
|
+
# trim_left
|
15
|
+
|
14
16
|
def run_trim_left_test expected, length, str = "something"
|
15
17
|
trimmed = Format.new.trim_left(str, length)
|
16
18
|
assert_equal expected, trimmed
|
@@ -28,21 +30,51 @@ module Logue
|
|
28
30
|
run_trim_left_test "some", -4
|
29
31
|
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
# trim_right
|
34
|
+
|
35
|
+
def assert_trim_right expected, length, str
|
36
|
+
trimmed = Format.new.trim_right str, length
|
37
|
+
assert_equal expected, trimmed, "length: #{length}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_trim_right_path_excess
|
41
|
+
assert_trim_right "ab/cd/ef.t", 11, "ab/cd/ef.t"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_trim_right_path_at_length
|
45
|
+
assert_trim_right "ab/cd/ef.t", 10, "ab/cd/ef.t"
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_trim_right_path_one_less
|
49
|
+
assert_trim_right ".../ef.t", 9, "ab/cd/ef.t"
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_trim_right_path_two_less
|
53
|
+
assert_trim_right ".../ef.t", 8, "ab/cd/ef.t"
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_trim_right_path_three_less
|
57
|
+
assert_trim_right "ef.t", 7, "ab/cd/ef.t"
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_trim_right_path_four_less
|
61
|
+
assert_trim_right "ef.t", 6, "ab/cd/ef.t"
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_trim_right_path_five_less
|
65
|
+
assert_trim_right "ef.t", 5, "ab/cd/ef.t"
|
34
66
|
end
|
35
67
|
|
36
|
-
def
|
37
|
-
|
68
|
+
def test_trim_right_path_six_less
|
69
|
+
assert_trim_right "ef.t", 4, "ab/cd/ef.t"
|
38
70
|
end
|
39
71
|
|
40
|
-
def
|
41
|
-
|
72
|
+
def test_trim_right_path_seven_less
|
73
|
+
assert_trim_right "ef.t", 3, "ab/cd/ef.t"
|
42
74
|
end
|
43
75
|
|
44
|
-
def
|
45
|
-
|
76
|
+
def test_trim_right_path_eight_less
|
77
|
+
assert_trim_right "ef.t", 2, "ab/cd/ef.t"
|
46
78
|
end
|
47
79
|
end
|
48
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Pace
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|