flexible_table 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6afdcaa9c791edd94485b031aaa33bc7fd321340
4
- data.tar.gz: a15377024136bc53e230a937b00f593c1f053fff
3
+ metadata.gz: 0b743ebb494954434ce4835b57d8692c1dcf54f5
4
+ data.tar.gz: 020c4ec648d16a4241becb7d0db83e75f4ea7468
5
5
  SHA512:
6
- metadata.gz: 98103dcb1b63f20fbe2856e8fb1679d0af978f918322fa8232ecba37da86c01c7230734748cca5a4555c47a465427a4ebc7f366ac7ab4cd56191f9a26489fc9d
7
- data.tar.gz: b031f5c477a71da528f2cde77ffd767f8390f59b832876b7add2b3391c93d6c25102188523d4342b15ab2b64ef5e28657d564711a39323d00c11a2aaa8d7b89c
6
+ metadata.gz: 426906c3b1c2189a16d420e73d0015f5a46cf486f9dd654e48ee8b0f8d010e4d369412baa9d77fa9da6c46dc32fb3411d0936eb12278952b0edc9a239c8dd227
7
+ data.tar.gz: 27a2a8088925e0f9d1da035171c8ff1c2a6647558d405698773813e34e3b04fa3c02a76cefa233dff989af81d71572e12218a77d296c46c7ae05a37fae4f67f9
@@ -1,7 +1,9 @@
1
1
  class FlexibleColumn
2
- def initialize(header, width_percentage)
2
+ def initialize(header, width_percentage, justify_row: :left, justify_header: :left)
3
3
  @header = header
4
4
  @width_percentage = width_percentage
5
+ @justify_row = justify_row
6
+ @justify_header = justify_header
5
7
  end
6
- attr_reader :width_percentage, :header
8
+ attr_reader :width_percentage, :header, :justify_row, :justify_header
7
9
  end
@@ -10,8 +10,8 @@ class FlexibleTable
10
10
  @columns = []
11
11
  end
12
12
 
13
- def add_column(title, width_percentage)
14
- @columns << FlexibleColumn.new(title, width_percentage)
13
+ def add_column(title, width_percentage, **args)
14
+ @columns << FlexibleColumn.new(title, width_percentage, args)
15
15
  end
16
16
 
17
17
  def print_header()
@@ -21,7 +21,13 @@ class FlexibleTable
21
21
  abs_width = get_abs_width(col.width_percentage, 3)
22
22
  output = get_printable_output(col.header, abs_width)
23
23
 
24
- printf("%-#{abs_width}s", output)
24
+ if(@columns[index].justify_header == :left)
25
+ printf("%-#{abs_width}s", output)
26
+ elsif(@columns[index].justify_header == :right)
27
+ printf("%#{abs_width}s", output)
28
+ else
29
+ printf("%-#{abs_width}s", output) # default to left justify
30
+ end
25
31
  printf(' | ') unless index == (@columns.length - 1)
26
32
  end
27
33
 
@@ -35,8 +41,15 @@ class FlexibleTable
35
41
  args.each_with_index do |element, index|
36
42
  abs_width = get_abs_width(@columns[index].width_percentage, 3)
37
43
  output = get_printable_output(element, abs_width)
38
-
39
- printf("%-#{abs_width}s", output)
44
+
45
+ if(@columns[index].justify_row == :left)
46
+ printf("%-#{abs_width}s", output)
47
+ elsif(@columns[index].justify_row == :right)
48
+ printf("%#{abs_width}s", output)
49
+ else
50
+ printf("%-#{abs_width}s", output) # default to left justify
51
+ end
52
+
40
53
  printf(' | ') unless index == (@columns.length - 1)
41
54
  end
42
55
  puts "\n"
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Sykes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-18 00:00:00.000000000 Z
11
+ date: 2016-10-02 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
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  version: '0'
41
41
  requirements: []
42
42
  rubyforge_project:
43
- rubygems_version: 2.4.5
43
+ rubygems_version: 2.5.1
44
44
  signing_key:
45
45
  specification_version: 4
46
46
  summary: Prints a table that can have different column widths that also respond in