array-formatter 1.0.3 → 1.1.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f425f92e125709cf78907cd802f408357da02cb
4
- data.tar.gz: a242f81025fdbcd0ce635033c81aae8292d26eef
3
+ metadata.gz: fbd2a1a21de7b4f6f5797a5b457283f7c8154dc3
4
+ data.tar.gz: 21e2c5ca9fb9223f76cc9a6e14dede1562f83e28
5
5
  SHA512:
6
- metadata.gz: e6660d02fc2bed960dcb21ded688b3e4b57c8e6f4184b8a1015fd4db003dcce25c45ec2976f2ce54f881401fe0058b4260e74e2c742d3c72fff5da5c453a2765
7
- data.tar.gz: 1ecd0884c2a48d2ae560b45ce5b1ae12f43559a4310263d2e19ce2586172a2b888cf0c0d8efdc340302e01aafdd56a79f5973fb205f1e8ad6f105516a7d6a99f
6
+ metadata.gz: b13479ed1888e51b59a08c4c0785a6205462fb899d6456c83ceb6beedd948fadf269f42acad179bdeb774e4c98232d700bd6ccf863f0e8e4e7f158ac60159a58
7
+ data.tar.gz: c9725d423fe73a85cb8a276e53c2b317d83dc495d809faee897fab949c77d6ce88cdb070a07fd0f68ffecfde3d37631d6d78026b5e701984cef4c72d0d297125
@@ -31,7 +31,7 @@ GEM
31
31
  multi_json (>= 1.5)
32
32
  mini_portile (0.5.2)
33
33
  minitest (5.3.0)
34
- multi_json (1.8.4)
34
+ multi_json (1.9.2)
35
35
  multi_xml (0.5.5)
36
36
  multipart-post (2.0.0)
37
37
  nokogiri (1.6.1)
@@ -43,7 +43,7 @@ GEM
43
43
  multi_xml (~> 0.5)
44
44
  rack (~> 1.2)
45
45
  rack (1.5.2)
46
- rake (10.1.1)
46
+ rake (10.3.1)
47
47
  rdoc (3.12.2)
48
48
  json (~> 1.4)
49
49
 
data/README.md CHANGED
@@ -25,18 +25,23 @@ Or install it yourself as:
25
25
 
26
26
  require 'array/formatter'
27
27
 
28
- array.to_table :ascii
29
- array.to_table :unicode
30
- array.to_table :unicode_double
31
- array.to_table :unicode_single
32
- array.to_table :unicode_mixed
33
-
28
+ array.to_table [CHARTYPE]
34
29
  array.to_csv
35
-
36
30
  array.to_html
37
-
38
31
  array.to_yaml
39
32
 
33
+ With the `to_table` method, `CHARTYPE` is one of following, and defaults
34
+ to `:ascii`:
35
+
36
+ :ascii
37
+ :unicode
38
+ :unicode_double
39
+ :unicode_single
40
+ :unicode_mixed
41
+
42
+ See `test/ref/*` for example outputs.
43
+
44
+
40
45
  ## Author:
41
46
 
42
47
  Alan K. Stebbens <aks@stebbens.org>
data/Rakefile CHANGED
@@ -33,7 +33,7 @@ Jeweler::Tasks.new do |gem|
33
33
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
34
34
  gem.require_paths = ["lib"]
35
35
  gem.add_development_dependency "bundler", "~> 1.3"
36
- gem.add_development_dependency "rake"
36
+ gem.add_development_dependency "rake", "~> 0"
37
37
  # dependencies defined in Gemfile
38
38
  end
39
39
  Jeweler::RubygemsDotOrgTasks.new
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: array-formatter 1.0.3 ruby lib
5
+ # stub: array-formatter 1.1.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "array-formatter"
9
- s.version = "1.0.3"
9
+ s.version = "1.1.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Alan K. Stebbens"]
14
- s.date = "2014-03-03"
14
+ s.date = "2014-05-04"
15
15
  s.description = " A simple gem to reformat an array of arrays into one of several string\n formats: HTML table; CSV; ASCII table; YAML\n"
16
16
  s.email = "aks@stebbens.org"
17
17
  s.extra_rdoc_files = [
@@ -35,19 +35,21 @@ Gem::Specification.new do |s|
35
35
  "test/ref/a-html.txt",
36
36
  "test/ref/a-unicode.txt",
37
37
  "test/ref/a-unicode_single.txt",
38
+ "test/ref/a-yaml.txt",
38
39
  "test/ref/b-ascii.txt",
39
40
  "test/ref/b-csv.txt",
40
41
  "test/ref/b-html.txt",
41
42
  "test/ref/b-unicode.txt",
42
43
  "test/ref/b-unicode_double.txt",
43
44
  "test/ref/b-unicode_mixed.txt",
45
+ "test/ref/b-yaml.txt",
44
46
  "test/test-array-formatter.rb"
45
47
  ]
46
48
  s.homepage = "https://bitbucket.org/aks_/array-formatter"
47
49
  s.licenses = ["MIT"]
48
50
  s.rubygems_version = "2.2.2"
49
51
  s.summary = "Format an array of arrays in one of serveral string formats"
50
- s.test_files = ["test/helper.rb", "test/ref/a-ascii.txt", "test/ref/a-csv.txt", "test/ref/a-html.txt", "test/ref/a-unicode.txt", "test/ref/a-unicode_single.txt", "test/ref/b-ascii.txt", "test/ref/b-csv.txt", "test/ref/b-html.txt", "test/ref/b-unicode.txt", "test/ref/b-unicode_double.txt", "test/ref/b-unicode_mixed.txt", "test/test-array-formatter.rb"]
52
+ s.test_files = ["test/helper.rb", "test/ref/a-ascii.txt", "test/ref/a-csv.txt", "test/ref/a-html.txt", "test/ref/a-unicode.txt", "test/ref/a-unicode_single.txt", "test/ref/a-yaml.txt", "test/ref/b-ascii.txt", "test/ref/b-csv.txt", "test/ref/b-html.txt", "test/ref/b-unicode.txt", "test/ref/b-unicode_double.txt", "test/ref/b-unicode_mixed.txt", "test/ref/b-yaml.txt", "test/test-array-formatter.rb"]
51
53
 
52
54
  if s.respond_to? :specification_version then
53
55
  s.specification_version = 4
@@ -57,20 +59,20 @@ Gem::Specification.new do |s|
57
59
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
58
60
  s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
59
61
  s.add_development_dependency(%q<bundler>, ["~> 1.3"])
60
- s.add_development_dependency(%q<rake>, [">= 0"])
62
+ s.add_development_dependency(%q<rake>, ["~> 0"])
61
63
  else
62
64
  s.add_dependency(%q<minitest>, ["~> 5.3"])
63
65
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
64
66
  s.add_dependency(%q<jeweler>, ["~> 2.0"])
65
67
  s.add_dependency(%q<bundler>, ["~> 1.3"])
66
- s.add_dependency(%q<rake>, [">= 0"])
68
+ s.add_dependency(%q<rake>, ["~> 0"])
67
69
  end
68
70
  else
69
71
  s.add_dependency(%q<minitest>, ["~> 5.3"])
70
72
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
71
73
  s.add_dependency(%q<jeweler>, ["~> 2.0"])
72
74
  s.add_dependency(%q<bundler>, ["~> 1.3"])
73
- s.add_dependency(%q<rake>, [">= 0"])
75
+ s.add_dependency(%q<rake>, ["~> 0"])
74
76
  end
75
77
  end
76
78
 
@@ -5,6 +5,7 @@
5
5
  # ARRAY.to_html -- format an array of arrays into an HTML table string
6
6
  # ARRAY.to_csv -- format an array of arrays into a CSV string
7
7
  # ARRAY.to_table -- format an array of arrays into an ASCII table string
8
+ # ARRAY.to_yaml -- format an array of arrays as a YAML string
8
9
  #
9
10
 
10
11
  class Array
@@ -53,7 +54,20 @@ class Array
53
54
  # characters.
54
55
 
55
56
  def to_csv
56
- self.map {|row| row.map {|f| f =~ /[[:punct:]]/ ? '"' + f.gsub(/"/, '""') + '"' : f }.join(",")}.join("\n")
57
+ self.map {|row|
58
+ row.map {|f|
59
+ f =~ /[[:punct:]]/ ? '"' + f.gsub(/"/, '""') + '"' : f }.
60
+ join(",")}.
61
+ join("\n")
62
+ end
63
+
64
+ # string = ARRAY.to_yaml
65
+ #
66
+ # Convert an array of arrays to YAML (using built-in core methods)
67
+
68
+ def to_yaml
69
+ require 'yaml'
70
+ YAML.dump(self)
57
71
  end
58
72
 
59
73
  # string = ARRAY.to_table type
@@ -149,13 +163,13 @@ class Array
149
163
  TableChars.new :unicode_double, [ "\u2554", "\u2550", "\u2566", "\u2557", # tlb, tb, tib, trb
150
164
  "\u2551", "\u2551", "\u2551", # ldb, idb, rdb
151
165
  "\u2560", "\u2550", "\u256C", "\u2563", # lib, ib, mib, rib
152
- "\u255A", "\u2550", "\u2569", "\u255D" ] # blb, bb, bib, brb
166
+ "\u255A", "\u2550", "\u2569", "\u255D" ] # blb, bb, bib, brb
153
167
 
154
168
  # :unicode_mixed - a table with double outer lines, and single inner lines
155
169
  TableChars.new :unicode_mixed, [ "\u2554", "\u2550", "\u2564", "\u2557", # tlb, tb, tib, trb
156
170
  "\u2551", "\u2502", "\u2551", # ldb, idb, rdb
157
171
  "\u255F", "\u2500", "\u253C", "\u2562", # lib, ib, mib, rib
158
- "\u255A", "\u2550", "\u2567", "\u255D" ] # blb, bb, bib, brb
172
+ "\u255A", "\u2550", "\u2567", "\u255D" ] # blb, bb, bib, brb
159
173
 
160
174
  TableChars.new :dos_single, [ "\xDA", "\xC4", "\xC2", "\xBF", # tlb, tb, tib, trb
161
175
  "\xB3", "\xB3", "\xB3", # ldb, idb, rdb
@@ -169,7 +183,7 @@ class Array
169
183
 
170
184
  TableChars.new :vt100, [ "\x6C", "\x71", "\x77", "\x6B", # tlb, tb, tib, trb
171
185
  "\x78", "\x78", "\x78", # ldb, idb, rdb,
172
- "\x74", "\x71", "\x6E", "\x75", # lib, ib, mib, rib
186
+ "\x74", "\x71", "\x6E", "\x75", # lib, ib, mib, rib
173
187
  "\xCD", "\x71", "\x76", "\x6A" ], # blb, bb, bib, brb
174
188
  "\e(0", "\e(B"
175
189
 
@@ -183,10 +197,10 @@ class Array
183
197
  # compute the maximum widths and the alignment of each column
184
198
  @widths = []
185
199
  @align = []
186
- self.each_with_index do |row,rx|
200
+ self.each_with_index do |row,rx|
187
201
  row.each_with_index do |col,cx|
188
202
  @widths[cx] ||= 0
189
- l = col.to_s.length
203
+ l = col.to_s.length
190
204
  @widths[cx] = l if l > @widths[cx]
191
205
  if rx == 0
192
206
  type = nil
@@ -213,11 +227,11 @@ class Array
213
227
  s
214
228
  end
215
229
 
216
- ##
230
+ ##
217
231
  # table_line position
218
232
  #
219
233
  # generate a table line for position (:top, :middle, :bottom)
220
- #
234
+ #
221
235
  def table_line position
222
236
  c = @chars
223
237
  left, line, mid, right = case position
@@ -1,3 +1,3 @@
1
1
  class Array::Formatter
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,4 +1,30 @@
1
- Company,Name,Address,Phone,Email
2
- New Company,First Last,"Somewhere, US","123-45-6789","user@sample.com"
3
- Old Company,First2 Last2,"Somewhere else, US","987-65-4321","user2@sample.com"
4
- No Company,First3 Last3,Elsewhere ZZ,"763-34-1234","user3@sample.com"
1
+ <table>
2
+ <tr>
3
+ <th>Company</th>
4
+ <th>Name</th>
5
+ <th>Address</th>
6
+ <th>Phone</th>
7
+ <th>Email</th>
8
+ </tr>
9
+ <tr>
10
+ <td>New Company</td>
11
+ <td>First Last</td>
12
+ <td>Somewhere, US</td>
13
+ <td>123-45-6789</td>
14
+ <td>user@sample.com</td>
15
+ </tr>
16
+ <tr>
17
+ <td>Old Company</td>
18
+ <td>First2 Last2</td>
19
+ <td>Somewhere else, US</td>
20
+ <td>987-65-4321</td>
21
+ <td>user2@sample.com</td>
22
+ </tr>
23
+ <tr>
24
+ <td>No Company</td>
25
+ <td>First3 Last3</td>
26
+ <td>Elsewhere ZZ</td>
27
+ <td>763-34-1234</td>
28
+ <td>user3@sample.com</td>
29
+ </tr>
30
+ </table>
@@ -0,0 +1,21 @@
1
+ ---
2
+ - - Company
3
+ - Name
4
+ - Address
5
+ - Phone
6
+ - Email
7
+ - - New Company
8
+ - First Last
9
+ - Somewhere, US
10
+ - 123-45-6789
11
+ - user@sample.com
12
+ - - Old Company
13
+ - First2 Last2
14
+ - Somewhere else, US
15
+ - 987-65-4321
16
+ - user2@sample.com
17
+ - - No Company
18
+ - First3 Last3
19
+ - Elsewhere ZZ
20
+ - 763-34-1234
21
+ - user3@sample.com
@@ -0,0 +1,25 @@
1
+ ---
2
+ - - Region
3
+ - State
4
+ - Sales
5
+ - - Northwest
6
+ - WA
7
+ - "$2,100,500"
8
+ - - Northwest
9
+ - OR
10
+ - "$900,800"
11
+ - - Northeast
12
+ - NY
13
+ - "$8,120,000"
14
+ - - Northeast
15
+ - MN
16
+ - "$489,500"
17
+ - - Southeast
18
+ - GA
19
+ - "$2,111,200"
20
+ - - Southeast
21
+ - FL
22
+ - "$9,388,000"
23
+ - - Southwest
24
+ - AZ
25
+ - "$7,377,000"
@@ -4,13 +4,13 @@ $LOAD_PATH.unshift '.', './test', './lib'
4
4
 
5
5
  $refdir = 'test/ref' # where the test reference output lives
6
6
 
7
- # if 'save' anywhere as an argument, the outputs are saved as reference
8
- # test output.
7
+ # if 'save' or '--save' appears anywhere as an argument, the outputs are saved
8
+ # as reference test output.
9
9
 
10
10
  $verbose = $save = nil
11
11
  ARGV.each_with_index do |arg, x|
12
12
  case arg
13
- when 'save'
13
+ when 'save', '--save'
14
14
  $save = true
15
15
  ARGV.delete_at(x)
16
16
  when '-v', '--verbose'
@@ -93,6 +93,7 @@ class Test_Array_Formatter < MiniTest::Unit::TestCase
93
93
  check s, :a, :unicode_single
94
94
  end
95
95
 
96
+
96
97
  def test_b_table_ascii
97
98
  s = @@b.to_table
98
99
  check s, :b, :ascii
@@ -122,11 +123,19 @@ class Test_Array_Formatter < MiniTest::Unit::TestCase
122
123
  end
123
124
 
124
125
  def test_a_to_html
125
- check @@a.to_csv, :a, :html
126
+ check @@a.to_html, :a, :html
126
127
  end
127
128
 
128
129
  def test_b_to_html
129
130
  check @@b.to_html, :b, :html
130
131
  end
131
132
 
133
+ def test_a_to_yaml
134
+ check @@a.to_yaml, :a, :yaml
135
+ end
136
+
137
+ def test_b_to_yaml
138
+ check @@b.to_yaml, :b, :yaml
139
+ end
140
+
132
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: array-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan K. Stebbens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-03 00:00:00.000000000 Z
11
+ date: 2014-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: |2
@@ -106,12 +106,14 @@ files:
106
106
  - test/ref/a-html.txt
107
107
  - test/ref/a-unicode.txt
108
108
  - test/ref/a-unicode_single.txt
109
+ - test/ref/a-yaml.txt
109
110
  - test/ref/b-ascii.txt
110
111
  - test/ref/b-csv.txt
111
112
  - test/ref/b-html.txt
112
113
  - test/ref/b-unicode.txt
113
114
  - test/ref/b-unicode_double.txt
114
115
  - test/ref/b-unicode_mixed.txt
116
+ - test/ref/b-yaml.txt
115
117
  - test/test-array-formatter.rb
116
118
  homepage: https://bitbucket.org/aks_/array-formatter
117
119
  licenses:
@@ -144,10 +146,12 @@ test_files:
144
146
  - test/ref/a-html.txt
145
147
  - test/ref/a-unicode.txt
146
148
  - test/ref/a-unicode_single.txt
149
+ - test/ref/a-yaml.txt
147
150
  - test/ref/b-ascii.txt
148
151
  - test/ref/b-csv.txt
149
152
  - test/ref/b-html.txt
150
153
  - test/ref/b-unicode.txt
151
154
  - test/ref/b-unicode_double.txt
152
155
  - test/ref/b-unicode_mixed.txt
156
+ - test/ref/b-yaml.txt
153
157
  - test/test-array-formatter.rb