simpletable 0.2.0 → 0.3.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.
- checksums.yaml +8 -8
- data/lib/simpletable/version.rb +1 -1
- data/lib/simpletable.rb +13 -10
- data/lib/test.rb +11 -19
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
YTA0Y2FiN2MwZGE2OTU0MzliMWZkZjQ3YzY5YjNjYWYxYmJhNjUzZQ==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
MjViZjdhOTJjZWRlMDhjNTU1NTMzYWU1MDljNmI4MTQzYTRhN2U5Mw==
|
|
7
7
|
!binary "U0hBNTEy":
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
NjdjMWRlMTI5Mjg1Njk4YjZjNGRkYTBlZDU4NzE3MGJjN2Y1NjBlNTllZDQ4
|
|
10
|
+
YTU5NjgzNjE0MzE0ZTQxNzQ3NDlkYjYzMjhiYzc0MTlhOWU0NDI0OWM0ZDMz
|
|
11
|
+
MjhiOWMwMGZjMDhiYzM5ZjEzZTlhNGU2YmJhNDlkODhlMTI0ZTE=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
M2Y1ZTNmMzc4YzM1ZjdlNmMwNDVkNGJkY2YzMWE3OTgxODRlMDIwNWQ4MmZk
|
|
14
|
+
ZDRmNDUyNmM1OWM0MjY0NmU2ZmE3OWE0ZmY1OWNlMmM4Yzk1NzBjYWIwNjgw
|
|
15
|
+
YzdmMjYyMjlkOTgyODkwMWRiYjZjZDBiMDIxZDFmMjIwZTY5OGI=
|
data/lib/simpletable/version.rb
CHANGED
data/lib/simpletable.rb
CHANGED
|
@@ -14,7 +14,7 @@ class SimpleTable
|
|
|
14
14
|
self
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def
|
|
17
|
+
def text
|
|
18
18
|
widths = []
|
|
19
19
|
# calculate column widths
|
|
20
20
|
@titles.zip(@methods).each do |title,method|
|
|
@@ -22,34 +22,37 @@ class SimpleTable
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
# print table header
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
text = row(@titles,widths)
|
|
26
|
+
text << (@divider * (widths.inject(:+) - @padding)) << "\n" # sum of column widths - padding
|
|
27
27
|
|
|
28
28
|
# print table body
|
|
29
29
|
@objects.each do |o|
|
|
30
30
|
data = @methods.collect{ |m| o.send(m) } # collect row data
|
|
31
|
-
|
|
31
|
+
text << row(data,widths)
|
|
32
32
|
end
|
|
33
|
+
text
|
|
33
34
|
end
|
|
34
35
|
|
|
35
|
-
def
|
|
36
|
+
def csv(separator=",")
|
|
36
37
|
# quote strings w/ embedded separator characters
|
|
37
38
|
titles = []
|
|
38
39
|
@titles.each {|t| titles << (t.include?(separator) ? t.gsub(t,"\"#{t}\"") : t)}
|
|
39
40
|
|
|
40
41
|
# print table header
|
|
41
|
-
|
|
42
|
+
text = titles.join(separator) << "\n"
|
|
42
43
|
|
|
43
44
|
# print table body
|
|
44
45
|
@objects.each do |o|
|
|
45
46
|
data = @methods.collect{ |m| o.send(m) } # collect row data
|
|
46
|
-
|
|
47
|
+
text << data.join(separator) << "\n"
|
|
47
48
|
end
|
|
49
|
+
text
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
private
|
|
51
|
-
def
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
def row(data,widths)
|
|
54
|
+
row = ""
|
|
55
|
+
data.zip(widths).each { |d,w| row << d.to_s.ljust(w) }
|
|
56
|
+
row << "\n"
|
|
54
57
|
end
|
|
55
58
|
end
|
data/lib/test.rb
CHANGED
|
@@ -24,22 +24,14 @@ objs << TestObject.new("thisisthebiggestword","thisisthebiggestword","thisistheb
|
|
|
24
24
|
|
|
25
25
|
t = SimpleTable.new
|
|
26
26
|
|
|
27
|
-
t.from_objects(objs,titles,methods).
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
t.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
t.
|
|
38
|
-
print "\n"
|
|
39
|
-
t.print_csv
|
|
40
|
-
print "\n"
|
|
41
|
-
|
|
42
|
-
t.from_objects(objs,titles2,methods,{:divider=>"-",:padding=>5}).print_text
|
|
43
|
-
print "\n"
|
|
44
|
-
t.print_csv(";")
|
|
45
|
-
print "\n"
|
|
27
|
+
puts t.from_objects(objs,titles,methods).text << "\n"
|
|
28
|
+
puts t.csv << "\n"
|
|
29
|
+
|
|
30
|
+
puts t.from_objects(objs,titles,methods,{:divider=>"*"}).text << "\n"
|
|
31
|
+
puts t.csv << "\n"
|
|
32
|
+
|
|
33
|
+
puts t.from_objects(objs,titles,methods,{:divider=>"-",:padding=>5}).text << "\n"
|
|
34
|
+
puts t.csv << "\n"
|
|
35
|
+
|
|
36
|
+
puts t.from_objects(objs,titles2,methods,{:divider=>"-",:padding=>5}).text << "\n"
|
|
37
|
+
puts t.csv(";") << "\n"
|