tabular 0.2.5 → 0.2.6
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/lib/tabular/table.rb +23 -17
- data/lib/tabular/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: decef6ce8a30ee4c9008445e52db1d8c6c7634da
|
4
|
+
data.tar.gz: 51165df09dc13e1c8f18c46eb2027f5755276490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faecd2bb8ddaee2e4f9776645c37407265fdf173484d8435d9796987f0d99c13fcd0ae80aa566320f790c6aea2dd69c20bf142cbb0c767f1db0ae633b34c3524
|
7
|
+
data.tar.gz: c26ddf3fcd83c9f7fda952d108e2d68547551580ea7ed655d1874a9800da37655c689aeb81d765e90188ab5c4487cedcff82bfbd25ca577dda30528b5210f645
|
data/lib/tabular/table.rb
CHANGED
@@ -76,15 +76,15 @@ module Tabular
|
|
76
76
|
def rows
|
77
77
|
@rows ||= []
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
# Set table rows. Calls row <<, which creates columns and links the source rows to Row#source.
|
81
81
|
def rows=(source_rows = [])
|
82
82
|
return [] unless source_rows
|
83
|
-
|
83
|
+
|
84
84
|
source_rows.each do |row|
|
85
85
|
self.<< row
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
rows
|
89
89
|
end
|
90
90
|
|
@@ -94,7 +94,7 @@ module Tabular
|
|
94
94
|
end
|
95
95
|
|
96
96
|
# Add row to end of table. Create missing columns and link the source row to Row#source.
|
97
|
-
# To control how source data is added to the Table, use Table#mapper= to set a class that
|
97
|
+
# To control how source data is added to the Table, use Table#mapper= to set a class that
|
98
98
|
# implements map(row) and returns a Hash.
|
99
99
|
def <<(row)
|
100
100
|
if row_mapper
|
@@ -126,24 +126,22 @@ module Tabular
|
|
126
126
|
end
|
127
127
|
|
128
128
|
# Remove all columns that only contain a blank string, zero, or nil
|
129
|
-
def delete_blank_columns!
|
130
|
-
|
129
|
+
def delete_blank_columns!(*_options)
|
130
|
+
exceptions = extract_exceptions(_options)
|
131
|
+
|
132
|
+
(columns.map(&:key) - exceptions).each do |key|
|
131
133
|
if rows.all? { |row| is_blank?(row[key]) || is_zero?(row[key]) }
|
132
134
|
delete_column key
|
133
135
|
end
|
134
136
|
end
|
135
137
|
end
|
136
|
-
|
138
|
+
|
137
139
|
# Remove all columns that contain the same value in all rows
|
138
140
|
def delete_homogenous_columns!(*_options)
|
139
141
|
return if rows.size < 2
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
else
|
144
|
-
exceptions = []
|
145
|
-
end
|
146
|
-
|
142
|
+
|
143
|
+
exceptions = extract_exceptions(_options)
|
144
|
+
|
147
145
|
(columns.map(&:key) - exceptions).each do |key|
|
148
146
|
value = rows.first[key]
|
149
147
|
if rows.all? { |row| row[key] == value }
|
@@ -151,7 +149,7 @@ module Tabular
|
|
151
149
|
end
|
152
150
|
end
|
153
151
|
end
|
154
|
-
|
152
|
+
|
155
153
|
# Remove preceding and trailing whitespace from all cells. By default, Table does not
|
156
154
|
# strip whitespace from cells.
|
157
155
|
def strip!
|
@@ -164,7 +162,7 @@ module Tabular
|
|
164
162
|
end
|
165
163
|
end
|
166
164
|
end
|
167
|
-
|
165
|
+
|
168
166
|
def delete_column(key)
|
169
167
|
rows.each do |row|
|
170
168
|
row.delete key
|
@@ -181,7 +179,7 @@ module Tabular
|
|
181
179
|
def renderers
|
182
180
|
columns.renderers
|
183
181
|
end
|
184
|
-
|
182
|
+
|
185
183
|
# Last-resort storage for client code data
|
186
184
|
def metadata
|
187
185
|
@metadata ||= {}
|
@@ -216,5 +214,13 @@ module Tabular
|
|
216
214
|
end
|
217
215
|
end
|
218
216
|
end
|
217
|
+
|
218
|
+
def extract_exceptions(options)
|
219
|
+
if options.first && options.first[:except]
|
220
|
+
options.first[:except]
|
221
|
+
else
|
222
|
+
[]
|
223
|
+
end
|
224
|
+
end
|
219
225
|
end
|
220
226
|
end
|
data/lib/tabular/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Willson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-ole
|