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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTk0MTBlYzY0Y2JhNDJkMzk5YTJhYTI1OGNjYTIyYzE2ZmQ3YWJiYw==
4
+ YTA0Y2FiN2MwZGE2OTU0MzliMWZkZjQ3YzY5YjNjYWYxYmJhNjUzZQ==
5
5
  data.tar.gz: !binary |-
6
- ZTY2MzliYmNkOTJmYjQ2OTRjMDdmZGZiOWRjNTE1YzQ1MWM3MzcyNw==
6
+ MjViZjdhOTJjZWRlMDhjNTU1NTMzYWU1MDljNmI4MTQzYTRhN2U5Mw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTI5Y2NmMjQzODZjNmRhNTVhNjIwZWMxYWNjOTJlYTM0ZmNkMDBkY2IyZTM0
10
- ZGUyNmE4MjI1MGQ5YmI1YjUyZWI3OTY4YTRmYjdmYmQ1OTZjZjkyMjQxZWE2
11
- YmVlMjBhMmJkZGFhZGFiMjE5NGNkZWZlYzhhMjYzNDNkOGEzZmI=
9
+ NjdjMWRlMTI5Mjg1Njk4YjZjNGRkYTBlZDU4NzE3MGJjN2Y1NjBlNTllZDQ4
10
+ YTU5NjgzNjE0MzE0ZTQxNzQ3NDlkYjYzMjhiYzc0MTlhOWU0NDI0OWM0ZDMz
11
+ MjhiOWMwMGZjMDhiYzM5ZjEzZTlhNGU2YmJhNDlkODhlMTI0ZTE=
12
12
  data.tar.gz: !binary |-
13
- OGU3MzQzMmQ0ZTIxMThjYjgyOGQ4ZDNlYjRmZWM4MzE2MTg5MWE2YTg3Zjg0
14
- NzI2N2RjZDIwZTNhZDI2OGNlYTUwODNkMDc3ZTFiNTA5ODBiNDUzN2NkYjFk
15
- MTY0NDhmOTZjZTdkMjJmNzAzNjVkZGE3ZjcwOWFjMjA0M2RjN2I=
13
+ M2Y1ZTNmMzc4YzM1ZjdlNmMwNDVkNGJkY2YzMWE3OTgxODRlMDIwNWQ4MmZk
14
+ ZDRmNDUyNmM1OWM0MjY0NmU2ZmE3OWE0ZmY1OWNlMmM4Yzk1NzBjYWIwNjgw
15
+ YzdmMjYyMjlkOTgyODkwMWRiYjZjZDBiMDIxZDFmMjIwZTY5OGI=
@@ -1,3 +1,3 @@
1
1
  module SimpleTableConst
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/simpletable.rb CHANGED
@@ -14,7 +14,7 @@ class SimpleTable
14
14
  self
15
15
  end
16
16
 
17
- def print_text
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
- print_row(@titles,widths)
26
- puts @divider * (widths.inject(:+) - @padding) # sum of column widths - padding
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
- print_row(data,widths)
31
+ text << row(data,widths)
32
32
  end
33
+ text
33
34
  end
34
35
 
35
- def print_csv(separator=",")
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
- puts titles.join separator
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
- puts data.join separator
47
+ text << data.join(separator) << "\n"
47
48
  end
49
+ text
48
50
  end
49
51
 
50
52
  private
51
- def print_row(data,widths)
52
- data.zip(widths).each { |d,w| print d.to_s.ljust(w) }
53
- print "\n"
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).print_text
28
- print "\n"
29
- t.print_csv
30
- print "\n"
31
-
32
- t.from_objects(objs,titles,methods,{:divider=>"*"}).print_text
33
- print "\n"
34
- t.print_csv
35
- print "\n"
36
-
37
- t.from_objects(objs,titles,methods,{:divider=>"-",:padding=>5}).print_text
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"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpletable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brady Turner