tabbit 0.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/tabbit.rb +79 -0
  3. metadata +73 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c0d6a286f06300091f46532073651188dd18b636
4
+ data.tar.gz: fbf069a06d3d3dd122e185dcb7c99c748b40a8b1
5
+ SHA512:
6
+ metadata.gz: 7fe77893d77f93ec1cbf976cf6746b523a552b4c985b4f08a78f4cbc8c9b681ebcd78135a07e24aa7617eca484b8fdb778139a6a91cea25e2e50b9fc35744f80
7
+ data.tar.gz: 8aab58f3d9c1e846bc78257728c25dd4ac1f4ca09d6979543b41f936c94ee7ae2fddc68d55943892786c3e6ce0778631d3388573d34405f19c4e9396f1ec3f8e
@@ -0,0 +1,79 @@
1
+ require 'toc'
2
+
3
+ class Tabbit
4
+ # When Tabbit.new is called, takes a undefined amount of headers to add
5
+ # to the table.
6
+ def initialize(*headers)
7
+ @table = [[]]
8
+ headers.each { |h| @table[0].push h }
9
+ end
10
+
11
+ def add_line(*items)
12
+ line = []
13
+ items.each { |i| line.push i }
14
+ @table.push line
15
+ end
16
+
17
+ def to_s
18
+ # Set instance variables for maximum length of each column
19
+ @table[0].length.times do |n|
20
+ self.instance_variable_set "@max_length_#{n}", 0.0
21
+ # Finds the longest string in column n and assign it to @max_length_n.
22
+ @table.each do |line|
23
+ if line[n].length > self.instance_variable_get("@max_length_#{n}")
24
+ self.instance_variable_set "@max_length_#{n}", line[n].length.to_f
25
+ end
26
+ end
27
+ end
28
+
29
+ divider '=', @table, new_line: true
30
+
31
+ # Write headers
32
+ @table[0].length.times do |n|
33
+ max_len = self.instance_variable_get("@max_length_#{n}")
34
+ difference = max_len - @table[0][n].length + 2
35
+
36
+ if @table[0][n] == @table[0].last
37
+ puts '|' + (' ' * 2) + @table[0][n].bold.red + (' ' * difference) + '|'
38
+ else
39
+ print '|' + (' ' * 2) + @table[0][n].bold.red + (' ' * difference)
40
+ end
41
+ end
42
+
43
+ divider '=', @table, new_line: true
44
+
45
+ # Write the table body, amount of spaces depends on the maximum length of
46
+ # that column.
47
+ @table.length.times do |n|
48
+ unless n == 0
49
+ line = @table[n]
50
+ line.length.times do |i|
51
+ item = line[i]
52
+ max_len2 = self.instance_variable_get("@max_length_#{i}")
53
+ difference2 = max_len2 - item.length + 2
54
+ if item == line.last
55
+ puts '|' + (' ' * 2) + item + (' ' * difference2) + '|'
56
+ else
57
+ print '|' + (' ' * 2) + item + (' ' * difference2)
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ divider '=', @table
64
+ end
65
+
66
+ private
67
+
68
+ # Takes the table being passed and calculates the width of the full table to write the divider.
69
+ def divider(split, table, options = {})
70
+ total_title_length = 0
71
+ table[0].length.times { |n| total_title_length += self.instance_variable_get("@max_length_#{n}") }
72
+
73
+ if options[:new_line]
74
+ puts split * ((table[0].length * 5) + total_title_length + 1)
75
+ else
76
+ print split * ((table[0].length * 5) + total_title_length + 1)
77
+ end
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tabbit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Green
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: toc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Toc is a simple tool used for colouring outputs to the console.
42
+ email: tiimgreen@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/tabbit.rb
48
+ homepage: https://github.com/tiimgreen/toc
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.1.11
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Colour your outputs to the console.
72
+ test_files: []
73
+ has_rdoc: