rgviz 0.26 → 0.27

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 (2) hide show
  1. data/lib/rgviz/csv_renderer.rb +36 -0
  2. metadata +4 -3
@@ -0,0 +1,36 @@
1
+ module Rgviz
2
+ module CsvRenderer
3
+ def self.render(table)
4
+ string = ''
5
+ table.cols.each_with_index do |row, i|
6
+ string << ',' if i > 0
7
+ string << CsvRenderer.format(row.label)
8
+ end
9
+
10
+ length = table.rows.length
11
+ string << "\n" if length > 0
12
+
13
+ table.rows.each_with_index do |row, i|
14
+ row.c.each_with_index do |col, i|
15
+ string << ',' if i > 0
16
+ string << CsvRenderer.format((col.f || col.v).to_s)
17
+ end
18
+ string << "\n" if i != length - 1
19
+ end
20
+ string
21
+ end
22
+
23
+ def self.format(value)
24
+ value = value.gsub('"', '""')
25
+
26
+ return "\"#{value}\"" if value.start_with?(' ') || value.end_with?(' ')
27
+
28
+ len = value.length
29
+ value.chars.each do |c|
30
+ return "\"#{value}\"" if c == ',' || c == "\n" || c == "\r" || c == "\t"
31
+ end
32
+
33
+ value
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgviz
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 26
9
- version: "0.26"
8
+ - 27
9
+ version: "0.27"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ary Borenszweig
@@ -28,6 +28,7 @@ extra_rdoc_files: []
28
28
 
29
29
  files:
30
30
  - lib/rgviz.rb
31
+ - lib/rgviz/csv_renderer.rb
31
32
  - lib/rgviz/html_renderer.rb
32
33
  - lib/rgviz/lexer.rb
33
34
  - lib/rgviz/nodes.rb