table_fu 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :minor: 3
3
3
  :build:
4
- :patch: 3
4
+ :patch: 4
5
5
  :major: 0
data/index.html CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  <body>
12
12
  <a href="http://www.propublica.org" class="propublica">&nbsp;</a>
13
- <h1>TableFu <small>&ndash; Version: 0.3.3</small></h1>
13
+ <h1>TableFu <small>&ndash; Version: 0.3.4</small></h1>
14
14
 
15
15
  <p><a href="http://github.com/propublica/table-fu">TableFu</a> is a ruby gem for spreadsheet-style handling of arrays (e.g. filtering, formatting, and sorting by "column" or "row"). In addition, it has the ability to <a href="#facet">facet</a> &mdash; or group &mdash; rows according to cell value. It was developed as a backend for its companion project <a href="http://www.github.com/propublica/table-setter">TableSetter</a>.</p>
16
16
  <p>For example, <strong>TableFu</strong> can consume a csv file and sort on a column:
@@ -276,8 +276,8 @@ class TableFu
276
276
  # And finally we return a empty string object or the value.
277
277
  #
278
278
  def to_s
279
- ret = if macro_value
280
- macro_value
279
+ ret = if macro?
280
+ macro_value.to_s
281
281
  elsif @spreadsheet.formatting && format_method = @spreadsheet.formatting[column_name]
282
282
  TableFu::Formatting.send(format_method, @datum) || ''
283
283
  else
@@ -287,10 +287,18 @@ class TableFu
287
287
  ret
288
288
  end
289
289
 
290
- # Returns the macro'd format if there is one
290
+ # Returns whether there is a macro format for this datum
291
291
  #
292
292
  # Returns:
293
- # The macro value if it exists, otherwise nil
293
+ # true if there is a macro format, false or nil otherwise
294
+ def macro?
295
+ @spreadsheet.formatting && @spreadsheet.formatting[@column_name].is_a?(Hash)
296
+ end
297
+
298
+ # Returns the macro'd format
299
+ #
300
+ # Returns:
301
+ # The macro value
294
302
  def macro_value
295
303
  # Grab the macro method first
296
304
  # Then get a array of the values in the columns listed as arguments
@@ -302,14 +310,12 @@ class TableFu
302
310
  #
303
311
  # in the above case we handle the AppendedColumn in this method
304
312
 
305
- if @spreadsheet.formatting && @spreadsheet.formatting[@column_name].is_a?(Hash)
306
- method = @spreadsheet.formatting[@column_name]['method']
307
- arguments = @spreadsheet.formatting[@column_name]['arguments'].inject([]) do |arr,arg|
308
- arr << @row.column_for(arg)
309
- arr
310
- end
311
- TableFu::Formatting.send(method, *arguments)
313
+ method = @spreadsheet.formatting[@column_name]['method']
314
+ arguments = @spreadsheet.formatting[@column_name]['arguments'].inject([]) do |arr,arg|
315
+ arr << @row.column_for(arg)
316
+ arr
312
317
  end
318
+ TableFu::Formatting.send(method, *arguments)
313
319
  end
314
320
 
315
321
  # Returns the raw value of a datum
@@ -184,6 +184,10 @@ describe TableFu, 'with macro columns' do
184
184
  "#{first}#{second}"
185
185
  end
186
186
 
187
+ def null(first)
188
+ nil
189
+ end
190
+
187
191
  end
188
192
 
189
193
  end
@@ -194,7 +198,8 @@ describe TableFu, 'with macro columns' do
194
198
  @spreadsheet = TableFu.new(csv)
195
199
  @spreadsheet.col_opts[:style] = {'Projects' => 'text-align:left;'}
196
200
  @spreadsheet.col_opts[:formatting] = {'Total Appropriation' => :currency,
197
- 'MacroColumn' => {'method' => 'append', 'arguments' => ['Projects','State']}}
201
+ 'MacroColumn' => {'method' => 'append', 'arguments' => ['Projects','State']},
202
+ 'NullColumn' => {'method' => 'null', 'arguments' => ['Projects']}}
198
203
  @spreadsheet.sorted_by = {'Projects' => {'order' => 'descending'}}
199
204
  @spreadsheet.col_opts[:columns] = ['State', 'Total Appropriation', 'Projects', 'MacroColumn']
200
205
  end
@@ -208,11 +213,14 @@ describe TableFu, 'with macro columns' do
208
213
  @spreadsheet.rows[1].column_for('Total Appropriation').to_s.should eql '$42,367,198'
209
214
  end
210
215
 
216
+ it "should allow macros that take arguments to return nil" do
217
+ @spreadsheet.rows[0].column_for('NullColumn').to_s.should eql ''
218
+ end
219
+
211
220
  it "should not barf if we try a bad formatter" do
212
221
  @spreadsheet.col_opts[:formatting] = {'Total Appropriation' => :bad_formatter }
213
222
  @spreadsheet.rows[1].column_for('Total Appropriation').to_s.should eql "bad_formatter not a valid formatter!"
214
223
  end
215
-
216
224
  end
217
225
 
218
226
  describe TableFu, 'with reordered columns' do
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{table_fu}
8
- s.version = "0.3.3"
8
+ s.version = "0.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Percival", "Jeff Larson"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_fu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 3
10
- version: 0.3.3
9
+ - 4
10
+ version: 0.3.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mark Percival