tablesmith 0.2.1 → 0.2.2
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 +2 -2
- data/lib/tablesmith/array_rows_source.rb +0 -44
- data/lib/tablesmith/hash_rows_base.rb +1 -0
- data/lib/tablesmith/hash_rows_source.rb +1 -1
- data/lib/tablesmith/table.rb +3 -0
- data/lib/tablesmith/version.rb +1 -1
- data/spec/hash_rows_table_spec.rb +40 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2debe86ed561ee342350d05b984e6519aafff2a
|
4
|
+
data.tar.gz: 64ab1246d907cb92b33e18bdf0a66ccea31047a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b4d1e2f5b10d150d9bb6d28c800030703a35a0a3196c4d941f7ed1e62618dfcadf89f1eaab183049b1f75284e63680ae2517489e26db578c5bc8fe0ffbd0073
|
7
|
+
data.tar.gz: ea5238cdeff276b012e3d7cecfbd061b486e5e3eda77e0d0c1adaaff07b7449db17289289ac7301fff132f5d4fe48178201edd2d781d49055889d005c2bafa7c
|
data/Gemfile.lock
CHANGED
@@ -8,14 +8,6 @@ module Tablesmith::ArrayRowsSource
|
|
8
8
|
item
|
9
9
|
end
|
10
10
|
|
11
|
-
# def flatten_hash_to_row(deep_hash, columns)
|
12
|
-
# row = ActiveSupport::OrderedHash.new
|
13
|
-
# columns.each do |col_or_hash|
|
14
|
-
# value_from_hash(row, deep_hash, col_or_hash)
|
15
|
-
# end
|
16
|
-
# row
|
17
|
-
# end
|
18
|
-
|
19
11
|
# TODO: no support for deep
|
20
12
|
def build_columns
|
21
13
|
@columns ||= []
|
@@ -29,40 +21,4 @@ module Tablesmith::ArrayRowsSource
|
|
29
21
|
column_names = rows.shift
|
30
22
|
grouped_headers(column_names) + [apply_column_aliases(column_names), :separator]
|
31
23
|
end
|
32
|
-
|
33
|
-
# def value_from_hash(row, deep_hash, col_or_hash)
|
34
|
-
# case col_or_hash
|
35
|
-
# when Tablesmith::Column
|
36
|
-
# row[col_or_hash.display_name] = deep_hash[col_or_hash.name]
|
37
|
-
# when Hash
|
38
|
-
# col_or_hash.each_pair do |sub_hash_key, cols_or_hash|
|
39
|
-
# [cols_or_hash].flatten.each do |inner_col_or_hash|
|
40
|
-
# value_from_hash(row, deep_hash[sub_hash_key], inner_col_or_hash)
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
# else
|
44
|
-
# nil
|
45
|
-
# end
|
46
|
-
# rescue => e
|
47
|
-
# $stderr.puts "#{e.message}: #{col_or_hash}" if @debug
|
48
|
-
# end
|
49
|
-
|
50
|
-
# def hash_rows_to_text_table(hash_rows)
|
51
|
-
# require 'text-table'
|
52
|
-
#
|
53
|
-
# header_row = hash_rows.first.keys
|
54
|
-
# table = []
|
55
|
-
# table << header_row
|
56
|
-
#
|
57
|
-
# hash_rows.each do |hash_row|
|
58
|
-
# row = []
|
59
|
-
# header_row.each do |header|
|
60
|
-
# row << hash_row[header]
|
61
|
-
# end
|
62
|
-
# table << row
|
63
|
-
# end
|
64
|
-
#
|
65
|
-
# # Array addition from text-table
|
66
|
-
# table.to_table(:first_row_is_head => true)
|
67
|
-
# end
|
68
24
|
end
|
@@ -7,6 +7,7 @@ module Tablesmith::HashRowsBase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def sort_columns(rows)
|
10
|
+
return if column_order.empty?
|
10
11
|
rows.map! do |row|
|
11
12
|
# this sort gives preference to column_order then falls back to alphabetic for leftovers.
|
12
13
|
# this is handy when columns auto-generate based on hash data.
|
@@ -30,7 +30,7 @@ module Tablesmith::HashRowsSource
|
|
30
30
|
def value_from_hash(row, deep_hash, col_or_hash)
|
31
31
|
case col_or_hash
|
32
32
|
when Tablesmith::Column
|
33
|
-
row[col_or_hash.display_name] = deep_hash[col_or_hash.name]
|
33
|
+
row[col_or_hash.display_name] = deep_hash[col_or_hash.name].to_s
|
34
34
|
when Hash
|
35
35
|
col_or_hash.each_pair do |sub_hash_key, cols_or_hash|
|
36
36
|
[cols_or_hash].flatten.each do |inner_col_or_hash|
|
data/lib/tablesmith/table.rb
CHANGED
@@ -128,6 +128,9 @@ class Array
|
|
128
128
|
def to_table
|
129
129
|
b = Tablesmith::Table.new(self)
|
130
130
|
|
131
|
+
# TODO: redesign such that every row is reacted to appropriately,
|
132
|
+
# so mixed content could be supported. Maybe every cell could be
|
133
|
+
# rendered appropriately, with nested tables.
|
131
134
|
if defined?(ActiveRecord) && defined?(ActiveRecord::Base)
|
132
135
|
if b.first && b.first.is_a?(ActiveRecord::Base)
|
133
136
|
b.extend Tablesmith::ActiveRecordSource
|
data/lib/tablesmith/version.rb
CHANGED
@@ -12,6 +12,28 @@ describe 'HashRowsSource' do
|
|
12
12
|
[{a: 1, b: 2}].to_table.text_table.to_s.should == expected
|
13
13
|
end
|
14
14
|
|
15
|
+
it 'outputs text table of hash row with nested Array' do
|
16
|
+
expected = <<~TABLE
|
17
|
+
+---+--------+
|
18
|
+
| a | b |
|
19
|
+
+---+--------+
|
20
|
+
| 1 | [1, 2] |
|
21
|
+
+---+--------+
|
22
|
+
TABLE
|
23
|
+
[{a: 1, b: [1, 2]}].to_table.text_table.to_s.should == expected
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'outputs text table of hash row with nested Hash' do
|
27
|
+
expected = <<~TABLE
|
28
|
+
+---+---------+
|
29
|
+
| a | b |
|
30
|
+
+---+---------+
|
31
|
+
| 1 | {:c=>3} |
|
32
|
+
+---+---------+
|
33
|
+
TABLE
|
34
|
+
[{a: 1, b: {c: 3}}].to_table.text_table.to_s.should == expected
|
35
|
+
end
|
36
|
+
|
15
37
|
it 'outputs text table of mixed columns hash rows with default columns' do
|
16
38
|
expected = <<~TABLE
|
17
39
|
+---+---+---+
|
@@ -30,9 +52,9 @@ describe 'HashRowsSource' do
|
|
30
52
|
it 'outputs text table of deep hash rows with defined columns' do
|
31
53
|
expected = <<~TABLE
|
32
54
|
+---+---+---+
|
33
|
-
|
|
55
|
+
| a | b |
|
34
56
|
+---+---+---+
|
35
|
-
|
|
57
|
+
| | c | d |
|
36
58
|
+---+---+---+
|
37
59
|
| 1 | 2 | 2 |
|
38
60
|
+---+---+---+
|
@@ -46,10 +68,25 @@ describe 'HashRowsSource' do
|
|
46
68
|
]}
|
47
69
|
]
|
48
70
|
end
|
49
|
-
|
71
|
+
|
72
|
+
# this would be nice.
|
50
73
|
# b.text_table.to_s.should == expected
|
51
74
|
pending
|
52
75
|
end
|
53
76
|
|
77
|
+
it 'keeps OrderedHash keys in order' do
|
78
|
+
h = ActiveSupport::OrderedHash.new
|
79
|
+
h[:z] = 2
|
80
|
+
h[:y] = 1
|
81
|
+
expected = <<~TABLE
|
82
|
+
+---+---+
|
83
|
+
| z | y |
|
84
|
+
+---+---+
|
85
|
+
| 2 | 1 |
|
86
|
+
+---+---+
|
87
|
+
TABLE
|
88
|
+
h.to_table.text_table.to_s.should == expected
|
89
|
+
end
|
90
|
+
|
54
91
|
it 'outputs text table of deep hash rows with default columns'
|
55
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tablesmith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chrismo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: text-table
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.6.13
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: Minimal console table
|