logue 1.0.4 → 1.0.5

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
  SHA1:
3
- metadata.gz: 3fd805ca22e710868ac6d67ff0bfbd6bed12ae0d
4
- data.tar.gz: 02bcbe756cb396977e02ebf1c4a0332718b38418
3
+ metadata.gz: 385cb8613ee04140fab6eacde15fa7ed4cb67ba1
4
+ data.tar.gz: e1e1649d69e92e3440dd02e43605debf063c72be
5
5
  SHA512:
6
- metadata.gz: e93458d58f660b7ebf5b0c424570c83715dd834a30699bf2c7c7ad2ea742487840b8e1fcd6ad5ee8c5a6cfae3040b0d56d93c2fffcfd9698a5dc200aa115178e
7
- data.tar.gz: e2fedbfd3769b43416dcfd59d9b9a0dc02873a3c275226b543e3dba3fab83d03017d6ff03a0c39894b5713f75ae76994c1b88526473d46e0d541bc3717fa7c8d
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
- path = str.split('/')
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
@@ -13,5 +13,5 @@ Pathname.glob(loguelibdir + '/logue/**/*.rb').each do |file|
13
13
  end
14
14
 
15
15
  module Logue
16
- VERSION = '1.0.4'
16
+ VERSION = '1.0.5'
17
17
  end
@@ -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
- def run_trim_right_test expected, length, str = "something"
32
- trimmed = Format.new.trim_right(str, length)
33
- assert_equal expected, trimmed
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 test_trim_right_short_positive_number
37
- run_trim_right_test " ...", 5
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 test_trim_right_long
41
- run_trim_right_test "something", 10
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 test_trim_right_short_negative_number
45
- run_trim_right_test " ...", -5
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
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-06 00:00:00.000000000 Z
11
+ date: 2016-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow