flexible_table 0.0.6 → 0.1.0

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: 7a73236157f1465ad66474d1c475d898977dccea
4
- data.tar.gz: 9ba1f14b2f739b0d970a4c7e8ddda1b1fd96b49a
3
+ metadata.gz: 261479ffb3fd0a07769c38069d4825d89d2b7819
4
+ data.tar.gz: f1fdc6517d7cefd042cb9a1485b48b3c529bc19f
5
5
  SHA512:
6
- metadata.gz: 683d19c3267c67c73420b7bcc232df3cc4882f243d7fffd756b972f286575342df7725271c877e364c73f4f6e8d1af86691f9ff6ec029327ffd9502820d235a2
7
- data.tar.gz: 008affeb040480939e8ef01245c93ecebac40a9b048e68f03e42c2df4ac9399bed8a1c4b3de62fb2ad9dfae572300e70ffca6a586745224e9eb85c0640595472
6
+ metadata.gz: b10b6d4e1a67862fbf230df48b2221730d9e69ad30bcdf7e3302aac466cf85ddc0f1c4d5584396fea4b5500c48a01ca246aab4862d21b09886df61e818e4e5fa
7
+ data.tar.gz: f11759ab17353d0cace5481c23e0145fded79f9b4d0869f8ab4ff7dea34f5642a03674a538134428d4cd4e9aa8aa9c613ee02ae0a0dcd6c03ff8c842ec803d7f
@@ -28,7 +28,7 @@ class FlexibleTable
28
28
  @columns << FlexibleColumn.new(title, width_percentage, args)
29
29
  end
30
30
 
31
- def print_header()
31
+ def print_header(io: $stdout)
32
32
  exit unless columns_fit_screen?(@columns)
33
33
 
34
34
  @columns.each_with_index do |col, index|
@@ -38,20 +38,20 @@ class FlexibleTable
38
38
  output = get_printable_output(col.header, abs_width)
39
39
 
40
40
  if(@columns[index].justify_header == :left)
41
- printf("%s%-#{abs_width}s%s", color_prefix, output, color_suffix)
41
+ io.printf("%s%-#{abs_width}s%s", color_prefix, output, color_suffix)
42
42
  elsif(@columns[index].justify_header == :right)
43
- printf("%s%#{abs_width}s%s", color_prefix, output, color_suffix)
43
+ io.printf("%s%#{abs_width}s%s", color_prefix, output, color_suffix)
44
44
  else
45
- printf("%s%-#{abs_width}s%s", color_prefix, output, color_suffix) # default to left justify
45
+ io.printf("%s%-#{abs_width}s%s", color_prefix, output, color_suffix) # default to left justify
46
46
  end
47
- print_column_separator unless index == (@columns.length - 1)
47
+ print_column_separator(io: io) unless index == (@columns.length - 1)
48
48
  end
49
49
 
50
- puts "\n"
51
- print_header_line(@total_screen_columns)
50
+ io.puts "\n"
51
+ print_header_line(@total_screen_columns, io: io)
52
52
  end
53
53
 
54
- def print_row(*args)
54
+ def print_row(*args, io: $stdout)
55
55
  exit unless columns_fit_screen?(@columns)
56
56
 
57
57
  args.each_with_index do |element, index|
@@ -61,15 +61,15 @@ class FlexibleTable
61
61
  output = get_printable_output(element, abs_width)
62
62
 
63
63
  if(@columns[index].justify_row == :left)
64
- printf("%s%-#{abs_width}s%s", color_prefix, output, color_suffix)
64
+ io.printf("%s%-#{abs_width}s%s", color_prefix, output, color_suffix)
65
65
  elsif(@columns[index].justify_row == :right)
66
- printf("%s%#{abs_width}s%s", color_prefix, output, color_suffix)
66
+ io.printf("%s%#{abs_width}s%s", color_prefix, output, color_suffix)
67
67
  else
68
- printf("%s%-#{abs_width}s%s", color_prefix, output, color_suffix) # default to left justify
68
+ io.printf("%s%-#{abs_width}s%s", color_prefix, output, color_suffix) # default to left justify
69
69
  end
70
70
 
71
- print_column_separator unless index == (@columns.length - 1)
71
+ print_column_separator(io: io) unless index == (@columns.length - 1)
72
72
  end
73
- puts "\n"
73
+ io.puts "\n"
74
74
  end
75
75
  end
data/lib/print_helper.rb CHANGED
@@ -30,7 +30,7 @@ module PrintHelper
30
30
  return str.to_s[0..(abs_width - 1)]
31
31
  end
32
32
 
33
- def print_header_line(total_screen_columns)
33
+ def print_header_line(total_screen_columns, io: stdout)
34
34
  line_header = ''
35
35
  separator = tty_supports_unicode? ? "\u2500" : '-'
36
36
 
@@ -39,7 +39,7 @@ module PrintHelper
39
39
  line_header << separator
40
40
  end
41
41
  end
42
- puts "#{line_header}\n"
42
+ io.puts "#{line_header}\n"
43
43
  end
44
44
 
45
45
  def columns_fit_screen?(columns)
@@ -55,10 +55,10 @@ module PrintHelper
55
55
  end
56
56
  end
57
57
 
58
- def print_column_separator
58
+ def print_column_separator(io: $stdout)
59
59
  separator = tty_supports_unicode? ? "\u2502" : '|'
60
60
 
61
- printf(" #{separator} ")
61
+ io.printf(" #{separator} ")
62
62
  end
63
63
 
64
64
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexible_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Sykes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-13 00:00:00.000000000 Z
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Prints a table that can have different column widths that also respond
14
14
  in size relative to the size of the terminal window
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  version: '0'
42
42
  requirements: []
43
43
  rubyforge_project:
44
- rubygems_version: 2.6.7
44
+ rubygems_version: 2.6.8
45
45
  signing_key:
46
46
  specification_version: 4
47
47
  summary: Prints a table that can have different column widths that also respond in