tabular 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c908df1467372314b8f4df918f660907f6783762
4
- data.tar.gz: 9c63253c7add9585952dc55cd2fe4e79701f1901
3
+ metadata.gz: decef6ce8a30ee4c9008445e52db1d8c6c7634da
4
+ data.tar.gz: 51165df09dc13e1c8f18c46eb2027f5755276490
5
5
  SHA512:
6
- metadata.gz: 9d4c2d9a66f85c6bbe76a045fad990565ebfab721df204a9a818e181794d55b86a272748766e61e82cdae2ed6ca93f3571cb8757639cc9ba3b05300ae5cd81d1
7
- data.tar.gz: 542cb560461e295a94adfe5f6864d185ae023874dd3d8c4905c65ad992c042a0c0296f5ea0c9e3c78a143aa106c20d128e8027010bb7ed2a03f791c248c0adda
6
+ metadata.gz: faecd2bb8ddaee2e4f9776645c37407265fdf173484d8435d9796987f0d99c13fcd0ae80aa566320f790c6aea2dd69c20bf142cbb0c767f1db0ae633b34c3524
7
+ data.tar.gz: c26ddf3fcd83c9f7fda952d108e2d68547551580ea7ed655d1874a9800da37655c689aeb81d765e90188ab5c4487cedcff82bfbd25ca577dda30528b5210f645
@@ -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
- columns.map(&:key).each do |key|
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
- if _options.first && _options.first[:except]
142
- exceptions = _options.first[:except]
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
@@ -1,3 +1,3 @@
1
1
  module Tabular
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
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.5
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-05-07 00:00:00.000000000 Z
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-ole