array-formatter 1.1.0 → 1.2.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 +4 -4
- data/Gemfile.lock +34 -24
- data/README.md +3 -1
- data/Rakefile +1 -1
- data/array-formatter.gemspec +31 -29
- data/lib/array/formatter.rb +27 -28
- data/lib/array/formatter/version.rb +1 -1
- data/test/helper.rb +2 -2
- data/test/ref/a-yml.txt +21 -0
- data/test/ref/b-yml.txt +25 -0
- data/test/test-array-formatter.rb +11 -12
- metadata +8 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e91718a160882cac0e81852a8dafe5e634dc2dea
|
|
4
|
+
data.tar.gz: dc6e3d1f8063bac2689cf50dadec9bbe7bb62aca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34da8710b7fe5533b336ced22b52f28f5591db8489008b7b676b23e011bfa7150acaf45be409569d72e262af39ac99f76c5eab7aa5c3022fd31e6ce2fffe9ab4
|
|
7
|
+
data.tar.gz: d5b8ae5563f6a72fd1b40d3c4c4a733f6c064b348e2f142b78af470eb91ae28be60f381e93bfcb178f883993a3681f34253075548d67b26d47a7aed33a615be1
|
data/Gemfile.lock
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
GEM
|
|
2
2
|
remote: http://rubygems.org/
|
|
3
3
|
specs:
|
|
4
|
-
addressable (2.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
addressable (2.5.0)
|
|
5
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
|
6
|
+
builder (3.2.3)
|
|
7
|
+
descendants_tracker (0.0.4)
|
|
8
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
|
9
|
+
faraday (0.9.2)
|
|
8
10
|
multipart-post (>= 1.2, < 3)
|
|
9
|
-
git (1.
|
|
11
|
+
git (1.3.0)
|
|
10
12
|
github_api (0.11.3)
|
|
11
13
|
addressable (~> 2.3)
|
|
12
14
|
descendants_tracker (~> 0.0.1)
|
|
@@ -15,37 +17,42 @@ GEM
|
|
|
15
17
|
multi_json (>= 1.7.5, < 2.0)
|
|
16
18
|
nokogiri (~> 1.6.0)
|
|
17
19
|
oauth2
|
|
18
|
-
hashie (
|
|
19
|
-
highline (1.
|
|
20
|
-
jeweler (2.
|
|
20
|
+
hashie (3.5.1)
|
|
21
|
+
highline (1.7.8)
|
|
22
|
+
jeweler (2.3.3)
|
|
21
23
|
builder
|
|
22
24
|
bundler (>= 1.0)
|
|
23
25
|
git (>= 1.2.5)
|
|
24
|
-
github_api
|
|
26
|
+
github_api (~> 0.11.0)
|
|
25
27
|
highline (>= 1.6.15)
|
|
26
28
|
nokogiri (>= 1.5.10)
|
|
29
|
+
psych (~> 2.2)
|
|
27
30
|
rake
|
|
28
31
|
rdoc
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
minitest (5.
|
|
34
|
-
multi_json (1.
|
|
35
|
-
multi_xml (0.
|
|
32
|
+
semver2
|
|
33
|
+
json (1.8.6)
|
|
34
|
+
jwt (1.5.6)
|
|
35
|
+
mini_portile2 (2.1.0)
|
|
36
|
+
minitest (5.10.1)
|
|
37
|
+
multi_json (1.12.1)
|
|
38
|
+
multi_xml (0.6.0)
|
|
36
39
|
multipart-post (2.0.0)
|
|
37
|
-
nokogiri (1.6.1)
|
|
38
|
-
|
|
39
|
-
oauth2 (
|
|
40
|
-
faraday (>= 0.8, < 0.
|
|
41
|
-
jwt (~>
|
|
40
|
+
nokogiri (1.6.8.1)
|
|
41
|
+
mini_portile2 (~> 2.1.0)
|
|
42
|
+
oauth2 (1.3.0)
|
|
43
|
+
faraday (>= 0.8, < 0.11)
|
|
44
|
+
jwt (~> 1.0)
|
|
42
45
|
multi_json (~> 1.3)
|
|
43
46
|
multi_xml (~> 0.5)
|
|
44
|
-
rack (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
rack (>= 1.2, < 3)
|
|
48
|
+
psych (2.2.2)
|
|
49
|
+
public_suffix (2.0.5)
|
|
50
|
+
rack (2.0.1)
|
|
51
|
+
rake (12.0.0)
|
|
47
52
|
rdoc (3.12.2)
|
|
48
53
|
json (~> 1.4)
|
|
54
|
+
semver2 (3.4.2)
|
|
55
|
+
thread_safe (0.3.5)
|
|
49
56
|
|
|
50
57
|
PLATFORMS
|
|
51
58
|
ruby
|
|
@@ -54,3 +61,6 @@ DEPENDENCIES
|
|
|
54
61
|
jeweler (~> 2.0)
|
|
55
62
|
minitest (~> 5.3)
|
|
56
63
|
rdoc (~> 3.12)
|
|
64
|
+
|
|
65
|
+
BUNDLED WITH
|
|
66
|
+
1.14.3
|
data/README.md
CHANGED
|
@@ -28,7 +28,9 @@ Or install it yourself as:
|
|
|
28
28
|
array.to_table [CHARTYPE]
|
|
29
29
|
array.to_csv
|
|
30
30
|
array.to_html
|
|
31
|
-
array.
|
|
31
|
+
array.to_yml
|
|
32
|
+
|
|
33
|
+
> Note: the `YAML` standard Ruby class defines a `to_yaml` method on arrays.
|
|
32
34
|
|
|
33
35
|
With the `to_table` method, `CHARTYPE` is one of following, and defaults
|
|
34
36
|
to `:ascii`:
|
data/Rakefile
CHANGED
|
@@ -18,7 +18,7 @@ require 'jeweler'
|
|
|
18
18
|
Jeweler::Tasks.new do |gem|
|
|
19
19
|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
|
20
20
|
gem.name = "array-formatter"
|
|
21
|
-
gem.homepage = "https://
|
|
21
|
+
gem.homepage = "https://github.com/aks/array-formatter"
|
|
22
22
|
gem.license = "MIT"
|
|
23
23
|
gem.version = Array::Formatter::VERSION
|
|
24
24
|
gem.summary = %Q{Format an array of arrays in one of serveral string formats}
|
data/array-formatter.gemspec
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
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.
|
|
5
|
+
# stub: array-formatter 1.2.0 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
|
-
s.name = "array-formatter"
|
|
9
|
-
s.version = "1.
|
|
8
|
+
s.name = "array-formatter".freeze
|
|
9
|
+
s.version = "1.2.0"
|
|
10
10
|
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
12
|
-
s.require_paths = ["lib"]
|
|
13
|
-
s.authors = ["Alan K. Stebbens"]
|
|
14
|
-
s.date = "
|
|
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
|
-
s.email = "aks@stebbens.org"
|
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
12
|
+
s.require_paths = ["lib".freeze]
|
|
13
|
+
s.authors = ["Alan K. Stebbens".freeze]
|
|
14
|
+
s.date = "2017-02-02"
|
|
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".freeze
|
|
16
|
+
s.email = "aks@stebbens.org".freeze
|
|
17
17
|
s.extra_rdoc_files = [
|
|
18
18
|
"LICENSE.txt",
|
|
19
19
|
"README.md"
|
|
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
|
|
|
36
36
|
"test/ref/a-unicode.txt",
|
|
37
37
|
"test/ref/a-unicode_single.txt",
|
|
38
38
|
"test/ref/a-yaml.txt",
|
|
39
|
+
"test/ref/a-yml.txt",
|
|
39
40
|
"test/ref/b-ascii.txt",
|
|
40
41
|
"test/ref/b-csv.txt",
|
|
41
42
|
"test/ref/b-html.txt",
|
|
@@ -43,36 +44,37 @@ Gem::Specification.new do |s|
|
|
|
43
44
|
"test/ref/b-unicode_double.txt",
|
|
44
45
|
"test/ref/b-unicode_mixed.txt",
|
|
45
46
|
"test/ref/b-yaml.txt",
|
|
47
|
+
"test/ref/b-yml.txt",
|
|
46
48
|
"test/test-array-formatter.rb"
|
|
47
49
|
]
|
|
48
|
-
s.homepage = "https://
|
|
49
|
-
s.licenses = ["MIT"]
|
|
50
|
-
s.rubygems_version = "2.
|
|
51
|
-
s.summary = "Format an array of arrays in one of serveral string formats"
|
|
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"]
|
|
50
|
+
s.homepage = "https://github.com/aks/array-formatter".freeze
|
|
51
|
+
s.licenses = ["MIT".freeze]
|
|
52
|
+
s.rubygems_version = "2.6.7".freeze
|
|
53
|
+
s.summary = "Format an array of arrays in one of serveral string formats".freeze
|
|
54
|
+
s.test_files = ["test/helper.rb".freeze, "test/ref/a-ascii.txt".freeze, "test/ref/a-csv.txt".freeze, "test/ref/a-html.txt".freeze, "test/ref/a-unicode.txt".freeze, "test/ref/a-unicode_single.txt".freeze, "test/ref/a-yaml.txt".freeze, "test/ref/a-yml.txt".freeze, "test/ref/b-ascii.txt".freeze, "test/ref/b-csv.txt".freeze, "test/ref/b-html.txt".freeze, "test/ref/b-unicode.txt".freeze, "test/ref/b-unicode_double.txt".freeze, "test/ref/b-unicode_mixed.txt".freeze, "test/ref/b-yaml.txt".freeze, "test/ref/b-yml.txt".freeze, "test/test-array-formatter.rb".freeze]
|
|
53
55
|
|
|
54
56
|
if s.respond_to? :specification_version then
|
|
55
57
|
s.specification_version = 4
|
|
56
58
|
|
|
57
59
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
58
|
-
s.add_development_dependency(%q<minitest
|
|
59
|
-
s.add_development_dependency(%q<rdoc
|
|
60
|
-
s.add_development_dependency(%q<jeweler
|
|
61
|
-
s.add_development_dependency(%q<bundler
|
|
62
|
-
s.add_development_dependency(%q<rake
|
|
60
|
+
s.add_development_dependency(%q<minitest>.freeze, ["~> 5.3"])
|
|
61
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
|
62
|
+
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.0"])
|
|
63
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.3"])
|
|
64
|
+
s.add_development_dependency(%q<rake>.freeze, ["~> 0"])
|
|
63
65
|
else
|
|
64
|
-
s.add_dependency(%q<minitest
|
|
65
|
-
s.add_dependency(%q<rdoc
|
|
66
|
-
s.add_dependency(%q<jeweler
|
|
67
|
-
s.add_dependency(%q<bundler
|
|
68
|
-
s.add_dependency(%q<rake
|
|
66
|
+
s.add_dependency(%q<minitest>.freeze, ["~> 5.3"])
|
|
67
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
|
68
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.0"])
|
|
69
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.3"])
|
|
70
|
+
s.add_dependency(%q<rake>.freeze, ["~> 0"])
|
|
69
71
|
end
|
|
70
72
|
else
|
|
71
|
-
s.add_dependency(%q<minitest
|
|
72
|
-
s.add_dependency(%q<rdoc
|
|
73
|
-
s.add_dependency(%q<jeweler
|
|
74
|
-
s.add_dependency(%q<bundler
|
|
75
|
-
s.add_dependency(%q<rake
|
|
73
|
+
s.add_dependency(%q<minitest>.freeze, ["~> 5.3"])
|
|
74
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
|
75
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.0"])
|
|
76
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.3"])
|
|
77
|
+
s.add_dependency(%q<rake>.freeze, ["~> 0"])
|
|
76
78
|
end
|
|
77
79
|
end
|
|
78
80
|
|
data/lib/array/formatter.rb
CHANGED
|
@@ -5,9 +5,12 @@
|
|
|
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.
|
|
8
|
+
# ARRAY.to_yml -- format an array of arrays as a YAML string
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
+
autoload :YAML, 'yaml'
|
|
12
|
+
autoload :CGI, 'cgi'
|
|
13
|
+
|
|
11
14
|
class Array
|
|
12
15
|
|
|
13
16
|
# string = ARRAY.to_html indent=0
|
|
@@ -16,18 +19,16 @@ class Array
|
|
|
16
19
|
# HTML table. If indent given, indent the <table> by that
|
|
17
20
|
# many spaces.
|
|
18
21
|
|
|
19
|
-
def to_html
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
s
|
|
22
|
+
def to_html(indent=0)
|
|
23
|
+
wrap_map_html_data("table", indent + 0) do |row, rx|
|
|
24
|
+
row.wrap_map_html_data("tr", indent + 1) do |field, fx|
|
|
25
|
+
tag = rx == 0 ? 'th' : 'td'
|
|
26
|
+
(' ' * (indent + 2)) + # indention
|
|
27
|
+
"<#{tag}>" + # open tag
|
|
28
|
+
(field && CGI.escapeHTML(field) || '') + # cell text
|
|
29
|
+
"</#{tag}>\n" # close tag
|
|
30
|
+
end
|
|
31
|
+
end
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
# string = ARRAY.wrap_map_html_data TAG, INDENT {|DATA, INDEX| block}
|
|
@@ -36,11 +37,11 @@ class Array
|
|
|
36
37
|
# <TAG> and ending with </TAG>, and invoking the block on each array item,
|
|
37
38
|
# passing the DATA item with its INDEX.
|
|
38
39
|
|
|
39
|
-
def wrap_map_html_data
|
|
40
|
+
def wrap_map_html_data(tag, indent=0)
|
|
40
41
|
s = ''
|
|
41
42
|
prefix = ' ' * indent
|
|
42
43
|
s << prefix + "<#{tag}>\n"
|
|
43
|
-
|
|
44
|
+
each_with_index {|data, x| s << ((yield data, x) || '') }
|
|
44
45
|
s << prefix + "</#{tag}>\n"
|
|
45
46
|
s
|
|
46
47
|
end
|
|
@@ -54,19 +55,18 @@ class Array
|
|
|
54
55
|
# characters.
|
|
55
56
|
|
|
56
57
|
def to_csv
|
|
57
|
-
|
|
58
|
+
map {|row|
|
|
58
59
|
row.map {|f|
|
|
59
60
|
f =~ /[[:punct:]]/ ? '"' + f.gsub(/"/, '""') + '"' : f }.
|
|
60
61
|
join(",")}.
|
|
61
62
|
join("\n")
|
|
62
63
|
end
|
|
63
64
|
|
|
64
|
-
# string = ARRAY.
|
|
65
|
+
# string = ARRAY.to_yml
|
|
65
66
|
#
|
|
66
67
|
# Convert an array of arrays to YAML (using built-in core methods)
|
|
67
68
|
|
|
68
|
-
def
|
|
69
|
-
require 'yaml'
|
|
69
|
+
def to_yml
|
|
70
70
|
YAML.dump(self)
|
|
71
71
|
end
|
|
72
72
|
|
|
@@ -109,7 +109,7 @@ class Array
|
|
|
109
109
|
@@table_chars = {}
|
|
110
110
|
@@table_char_names = %w( tlb tb tib trb ldb idb rdb lib ib mib rib blb bb bib brb ).map{|n|n.intern}
|
|
111
111
|
|
|
112
|
-
def initialize
|
|
112
|
+
def initialize(name, fmt_chars, start=nil, stop=nil)
|
|
113
113
|
@chars = self
|
|
114
114
|
@@table_chars[name] = @chars
|
|
115
115
|
if fmt_chars.class == Symbol
|
|
@@ -131,13 +131,13 @@ class Array
|
|
|
131
131
|
#
|
|
132
132
|
# Return the TableChars object for NAME, or nil
|
|
133
133
|
|
|
134
|
-
def self.get
|
|
134
|
+
def self.get(name)
|
|
135
135
|
@chars = @@table_chars[name]
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
attr_reader :start, :stop
|
|
139
139
|
|
|
140
|
-
def wrap
|
|
140
|
+
def wrap(text)
|
|
141
141
|
(@start || '') + text + (@stop || '')
|
|
142
142
|
end
|
|
143
143
|
|
|
@@ -190,14 +190,13 @@ class Array
|
|
|
190
190
|
TableChars.new :unicode, :unicode_single
|
|
191
191
|
TableChars.new :dos, :dos_single
|
|
192
192
|
|
|
193
|
-
|
|
194
|
-
def to_table name=:ascii
|
|
193
|
+
def to_table(name=:ascii)
|
|
195
194
|
@chars = TableChars.get name
|
|
196
195
|
|
|
197
196
|
# compute the maximum widths and the alignment of each column
|
|
198
197
|
@widths = []
|
|
199
198
|
@align = []
|
|
200
|
-
|
|
199
|
+
each_with_index do |row,rx|
|
|
201
200
|
row.each_with_index do |col,cx|
|
|
202
201
|
@widths[cx] ||= 0
|
|
203
202
|
l = col.to_s.length
|
|
@@ -219,7 +218,7 @@ class Array
|
|
|
219
218
|
|
|
220
219
|
# now format each row
|
|
221
220
|
s = ''
|
|
222
|
-
|
|
221
|
+
each_with_index do |row, rx|
|
|
223
222
|
s << table_line(rx == 0 ? :top : :middle)
|
|
224
223
|
s << table_data(row)
|
|
225
224
|
end
|
|
@@ -232,7 +231,7 @@ class Array
|
|
|
232
231
|
#
|
|
233
232
|
# generate a table line for position (:top, :middle, :bottom)
|
|
234
233
|
#
|
|
235
|
-
def table_line
|
|
234
|
+
def table_line(position)
|
|
236
235
|
c = @chars
|
|
237
236
|
left, line, mid, right = case position
|
|
238
237
|
when :top then [c[:tlb], c[:tb], c[:tib], c[:trb]]
|
|
@@ -248,7 +247,7 @@ class Array
|
|
|
248
247
|
#
|
|
249
248
|
# generate a data row as part of a table
|
|
250
249
|
|
|
251
|
-
def table_data
|
|
250
|
+
def table_data(data)
|
|
252
251
|
left, middle, right = [@chars[:ldb], @chars[:idb], @chars[:rdb]]
|
|
253
252
|
a = []
|
|
254
253
|
data.each_with_index do |item, x|
|
data/test/helper.rb
CHANGED
data/test/ref/a-yml.txt
ADDED
|
@@ -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
|
data/test/ref/b-yml.txt
ADDED
|
@@ -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"
|
|
@@ -19,15 +19,15 @@ ARGV.each_with_index do |arg, x|
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
require 'helper'
|
|
22
|
-
|
|
22
|
+
require 'array/formatter'
|
|
23
23
|
|
|
24
|
-
class Test_Array_Formatter < MiniTest::
|
|
24
|
+
class Test_Array_Formatter < MiniTest::Test
|
|
25
25
|
|
|
26
|
-
def ref_filename
|
|
26
|
+
def ref_filename(name, kind)
|
|
27
27
|
"#{$refdir}/#{name}-#{kind}.txt"
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
def read_ref
|
|
30
|
+
def read_ref(name, kind)
|
|
31
31
|
filename = ref_filename(name, kind)
|
|
32
32
|
ref = nil
|
|
33
33
|
if File.exist?(filename)
|
|
@@ -36,7 +36,7 @@ class Test_Array_Formatter < MiniTest::Unit::TestCase
|
|
|
36
36
|
ref
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def write_ref
|
|
39
|
+
def write_ref(name, kind, out)
|
|
40
40
|
filename = ref_filename(name, kind)
|
|
41
41
|
unless Dir.exist?($refdir)
|
|
42
42
|
Dir.mkdir $refdir
|
|
@@ -46,7 +46,7 @@ class Test_Array_Formatter < MiniTest::Unit::TestCase
|
|
|
46
46
|
printf "%d lines written to %s\n", (out.count("\n")+1), filename
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def check
|
|
49
|
+
def check(actual, name, kind)
|
|
50
50
|
if $verbose
|
|
51
51
|
puts ""
|
|
52
52
|
puts actual
|
|
@@ -56,7 +56,7 @@ class Test_Array_Formatter < MiniTest::Unit::TestCase
|
|
|
56
56
|
if expected
|
|
57
57
|
assert_equal actual.strip, expected.strip, "Error: at #{caller.first}:"
|
|
58
58
|
else
|
|
59
|
-
puts "No reference output to compare with"
|
|
59
|
+
puts "No reference output to compare with (at #{caller.first})"
|
|
60
60
|
end
|
|
61
61
|
else
|
|
62
62
|
write_ref name, kind, actual
|
|
@@ -93,7 +93,6 @@ class Test_Array_Formatter < MiniTest::Unit::TestCase
|
|
|
93
93
|
check s, :a, :unicode_single
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
-
|
|
97
96
|
def test_b_table_ascii
|
|
98
97
|
s = @@b.to_table
|
|
99
98
|
check s, :b, :ascii
|
|
@@ -130,12 +129,12 @@ class Test_Array_Formatter < MiniTest::Unit::TestCase
|
|
|
130
129
|
check @@b.to_html, :b, :html
|
|
131
130
|
end
|
|
132
131
|
|
|
133
|
-
def
|
|
134
|
-
check @@a.
|
|
132
|
+
def test_a_to_yml
|
|
133
|
+
check @@a.to_yml, :a, :yml
|
|
135
134
|
end
|
|
136
135
|
|
|
137
|
-
def
|
|
138
|
-
check @@b.
|
|
136
|
+
def test_b_to_yml
|
|
137
|
+
check @@b.to_yml, :b, :yml
|
|
139
138
|
end
|
|
140
139
|
|
|
141
140
|
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.
|
|
4
|
+
version: 1.2.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:
|
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -107,6 +107,7 @@ files:
|
|
|
107
107
|
- test/ref/a-unicode.txt
|
|
108
108
|
- test/ref/a-unicode_single.txt
|
|
109
109
|
- test/ref/a-yaml.txt
|
|
110
|
+
- test/ref/a-yml.txt
|
|
110
111
|
- test/ref/b-ascii.txt
|
|
111
112
|
- test/ref/b-csv.txt
|
|
112
113
|
- test/ref/b-html.txt
|
|
@@ -114,8 +115,9 @@ files:
|
|
|
114
115
|
- test/ref/b-unicode_double.txt
|
|
115
116
|
- test/ref/b-unicode_mixed.txt
|
|
116
117
|
- test/ref/b-yaml.txt
|
|
118
|
+
- test/ref/b-yml.txt
|
|
117
119
|
- test/test-array-formatter.rb
|
|
118
|
-
homepage: https://
|
|
120
|
+
homepage: https://github.com/aks/array-formatter
|
|
119
121
|
licenses:
|
|
120
122
|
- MIT
|
|
121
123
|
metadata: {}
|
|
@@ -135,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
135
137
|
version: '0'
|
|
136
138
|
requirements: []
|
|
137
139
|
rubyforge_project:
|
|
138
|
-
rubygems_version: 2.
|
|
140
|
+
rubygems_version: 2.6.7
|
|
139
141
|
signing_key:
|
|
140
142
|
specification_version: 4
|
|
141
143
|
summary: Format an array of arrays in one of serveral string formats
|
|
@@ -147,6 +149,7 @@ test_files:
|
|
|
147
149
|
- test/ref/a-unicode.txt
|
|
148
150
|
- test/ref/a-unicode_single.txt
|
|
149
151
|
- test/ref/a-yaml.txt
|
|
152
|
+
- test/ref/a-yml.txt
|
|
150
153
|
- test/ref/b-ascii.txt
|
|
151
154
|
- test/ref/b-csv.txt
|
|
152
155
|
- test/ref/b-html.txt
|
|
@@ -154,4 +157,5 @@ test_files:
|
|
|
154
157
|
- test/ref/b-unicode_double.txt
|
|
155
158
|
- test/ref/b-unicode_mixed.txt
|
|
156
159
|
- test/ref/b-yaml.txt
|
|
160
|
+
- test/ref/b-yml.txt
|
|
157
161
|
- test/test-array-formatter.rb
|