tabbit 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tabbit.rb +15 -20
- 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: 1e74b496c1b7aa3e9247a178e6f8137fe2f6050d
|
4
|
+
data.tar.gz: 7e5b1e0b423718daf4c896bfb59aed07bc2b43d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03206392d362f91bfa639b129d759184040a820cc2745acd7e45873b8beba2b53d67bebcdadd3b8f7572a0e737bd20bdcfa70b4d0582572e027b940127299404
|
7
|
+
data.tar.gz: 0f86fd43b7895c6c4728b2758b0ba16d3c7b451a2dd7e2381572d6645ea904f903ce8981249b93a3e8e85381c81c85effe407db999a2d28318b2eb33b867396f
|
data/lib/tabbit.rb
CHANGED
@@ -11,7 +11,7 @@ class Tabbit
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Adds line to @table in form of Array
|
14
|
-
def
|
14
|
+
def add_row(*items)
|
15
15
|
line = []
|
16
16
|
items.each { |i| line.push i }
|
17
17
|
@table.push line
|
@@ -19,10 +19,10 @@ class Tabbit
|
|
19
19
|
|
20
20
|
# Changes @table Array into format for printing to console.
|
21
21
|
def to_s
|
22
|
-
# Set instance variables for maximum length of each column
|
23
22
|
@table[0].length.times do |n|
|
24
23
|
self.instance_variable_set "@max_length_#{n}", 0.0
|
25
|
-
|
24
|
+
|
25
|
+
# Finds the longest string in column
|
26
26
|
@table.each do |line|
|
27
27
|
if line[n].length > self.instance_variable_get("@max_length_#{n}")
|
28
28
|
self.instance_variable_set "@max_length_#{n}", line[n].length.to_f
|
@@ -32,16 +32,11 @@ class Tabbit
|
|
32
32
|
|
33
33
|
divider '=', @table, new_line: true
|
34
34
|
|
35
|
-
# Write headers
|
36
35
|
@table[0].length.times do |n|
|
37
|
-
|
38
|
-
difference = max_len - @table[0][n].length + 2
|
36
|
+
difference = self.instance_variable_get("@max_length_#{n}") - @table[0][n].length + 2
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
else
|
43
|
-
print '|' + (' ' * 2) + @table[0][n].bold.red + (' ' * difference)
|
44
|
-
end
|
38
|
+
cell = '|' + (' ' * 2) + @table[0][n].bold.red + (' ' * difference)
|
39
|
+
@table[0][n] == @table[0].last ? puts(cell + '|') : print(cell)
|
45
40
|
end
|
46
41
|
|
47
42
|
divider '=', @table, new_line: true
|
@@ -53,13 +48,9 @@ class Tabbit
|
|
53
48
|
line = @table[n]
|
54
49
|
line.length.times do |i|
|
55
50
|
item = line[i]
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
puts '|' + (' ' * 2) + item + (' ' * difference2) + '|'
|
60
|
-
else
|
61
|
-
print '|' + (' ' * 2) + item + (' ' * difference2)
|
62
|
-
end
|
51
|
+
difference = self.instance_variable_get("@max_length_#{i}") - item.length + 2
|
52
|
+
cell = '|' + (' ' * 2) + item + (' ' * difference)
|
53
|
+
item == line.last ? puts(cell + '|') : print(cell)
|
63
54
|
end
|
64
55
|
end
|
65
56
|
end
|
@@ -67,13 +58,17 @@ class Tabbit
|
|
67
58
|
divider '=', @table
|
68
59
|
end
|
69
60
|
|
61
|
+
def size
|
62
|
+
@table.length - 1
|
63
|
+
end
|
64
|
+
|
70
65
|
private
|
71
66
|
|
72
67
|
# Takes the table being passed and calculates the width of the full table to write the divider.
|
73
|
-
def divider(
|
68
|
+
def divider(char, table, options = {})
|
74
69
|
total_title_length = 0
|
75
70
|
table[0].length.times { |n| total_title_length += self.instance_variable_get("@max_length_#{n}") }
|
76
|
-
statement =
|
71
|
+
statement = char * ((table[0].length * 5) + total_title_length + 1)
|
77
72
|
|
78
73
|
options[:new_line] ? puts(statement) : print(statement)
|
79
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Green
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|