tabbit 0.0.1 → 0.0.2

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 +4 -4
  2. data/lib/tabbit.rb +15 -20
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94308328d60f339509c995c85f7c4422caad16f9
4
- data.tar.gz: a38b7cdba853b47590d62057b1462df11349d63d
3
+ metadata.gz: 1e74b496c1b7aa3e9247a178e6f8137fe2f6050d
4
+ data.tar.gz: 7e5b1e0b423718daf4c896bfb59aed07bc2b43d1
5
5
  SHA512:
6
- metadata.gz: 5196b63840a753d4c55fb875d4f789413ea7f7efc904adc6db04afe26eadf7ac494153ed4cca9f66343adea49d4f17315b32f5802fb2719870dfdf30462e3c83
7
- data.tar.gz: 9eaac2f4f46edb772451cfe8486dbddde7e201fb3228609138ff509c834c14949b8e721e0cc4d99fe865e0126ff0a22580b835d58dd3201e68a773ad2c010a4d
6
+ metadata.gz: 03206392d362f91bfa639b129d759184040a820cc2745acd7e45873b8beba2b53d67bebcdadd3b8f7572a0e737bd20bdcfa70b4d0582572e027b940127299404
7
+ data.tar.gz: 0f86fd43b7895c6c4728b2758b0ba16d3c7b451a2dd7e2381572d6645ea904f903ce8981249b93a3e8e85381c81c85effe407db999a2d28318b2eb33b867396f
@@ -11,7 +11,7 @@ class Tabbit
11
11
  end
12
12
 
13
13
  # Adds line to @table in form of Array
14
- def add_line(*items)
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
- # Finds the longest string in column n and assign it to @max_length_n.
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
- max_len = self.instance_variable_get("@max_length_#{n}")
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
- if @table[0][n] == @table[0].last
41
- puts '|' + (' ' * 2) + @table[0][n].bold.red + (' ' * difference) + '|'
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
- max_len_of_column = self.instance_variable_get("@max_length_#{i}")
57
- difference2 = max_len_of_column - item.length + 2 # Spaces needed after item in column.
58
- if item == line.last
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(split, table, options = {})
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 = split * ((table[0].length * 5) + total_title_length + 1)
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.1
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-09 00:00:00.000000000 Z
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec