table_fu 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :minor: 2
3
- :patch: 1
2
+ :patch: 0
4
3
  :build:
5
4
  :major: 0
5
+ :minor: 3
@@ -2,4 +2,4 @@ spreadsheet = TableFu.new(csv) do |s|
2
2
  s.columns = ["Best Book", "Author"]
3
3
  end
4
4
 
5
- spreadsheet.rows[0].column_for('Style').to_s
5
+ spreadsheet.rows[0]['Style'].to_s
data/index.html CHANGED
@@ -1,196 +0,0 @@
1
-
2
- <!DOCTYPE html>
3
- <html>
4
- <head>
5
- <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
6
- <title>TableFu</title>
7
- <link rel="stylesheet" type="text/css" href="documentation/css/styles.css" />
8
- <link rel="stylesheet" type="text/css" href="documentation/css/dawn.css" />
9
- </head>
10
-
11
- <body>
12
- <a href="http://www.propublica.org" class="propublica">&nbsp;</a>
13
- <h1>TableFu <small>&ndash; Version: 0.2.0</small></h1>
14
-
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
- <p>For example, <strong>TableFu</strong> can consume a csv file and sort on a column:
17
- <pre class="dawn">csv <span class="Keyword">=</span>&lt;&lt;-CSV
18
- Author,Best Book,Number of Pages,Style
19
- Samuel Beckett,Malone Muert,120,Modernism
20
- James Joyce,Ulysses,644,Modernism
21
- Nicholson Baker,Mezannine,150,Minimalism
22
- Vladimir Sorokin,The Queue,263,Satire
23
- CSV
24
-
25
- spreadsheet <span class="Keyword">=</span> <span class="Support">TableFu</span><span class="PunctuationSeparator">.</span><span class="Entity">new</span>(csv) <span class="Keyword">do </span><span class="PunctuationSeparator">|</span><span class="Variable">s</span><span class="PunctuationSeparator">|</span>
26
- s<span class="PunctuationSeparator">.</span><span class="Entity">sorted_by</span> <span class="Keyword">=</span> {'Best Book' <span class="PunctuationSeparator">=&gt;</span> {'order' <span class="PunctuationSeparator">=&gt;</span> 'ascending'}}
27
- <span class="Keyword">end</span>
28
- </pre><em>Returns:</em><pre class="dawn">[[&quot;Samuel Beckett&quot;<span class="PunctuationSeparator">,</span> &quot;Malone Muert&quot;<span class="PunctuationSeparator">,</span> &quot;120&quot;<span class="PunctuationSeparator">,</span> &quot;Modernism&quot;]<span class="PunctuationSeparator">,</span> [&quot;Nicholson Baker&quot;<span class="PunctuationSeparator">,</span> &quot;Mezannine&quot;<span class="PunctuationSeparator">,</span> &quot;150&quot;<span class="PunctuationSeparator">,</span> &quot;Minimalism&quot;]<span class="PunctuationSeparator">,</span> [&quot;Vladimir Sorokin&quot;<span class="PunctuationSeparator">,</span> &quot;The Queue&quot;<span class="PunctuationSeparator">,</span> &quot;263&quot;<span class="PunctuationSeparator">,</span> &quot;Satire&quot;]<span class="PunctuationSeparator">,</span> [&quot;James Joyce&quot;<span class="PunctuationSeparator">,</span> &quot;Ulysses&quot;<span class="PunctuationSeparator">,</span> &quot;644&quot;<span class="PunctuationSeparator">,</span> &quot;Modernism&quot;]]
29
- </pre>
30
- </p>
31
- <h2><a id="toc">Table of Contents</a></h2>
32
- <ul>
33
- <li><a href="#installation">Installation</a></li>
34
- <li><a href="#usage">Usage</a></li>
35
- <li><a href="#macros">Macros / Formatting</a></li>
36
- <li><a href="#faceting">Faceting</a></li>
37
- <li><a href="#manipulation">Manipulation</a></li>
38
- <li><a href="#links">Links</a></li>
39
- <li><a href="#credits">Credits</a></li>
40
- <li><a href="#license">License</a></li>
41
- </ul>
42
- <h2><a id="installation" href="#toc">Installation</a></h2>
43
- <p><strong>TableFu</strong> is available as a rubygem:
44
- <pre class="dawn">
45
- gem install table_fu</pre>
46
- or from the actual source:
47
- <pre class="dawn">
48
- git clone git://github.com/propublica/table-fu.git
49
- cd table-fu
50
- rake install</pre>
51
- </p>
52
- <h2><a id="usage" href="#toc">Usage</a></h2>
53
- <p>
54
- The <strong>TableFu</strong> constructor takes two arguments; a 2 dimensional array or csv (file object or string) and a hash of column options or a block. TableFu will assume that the first row of the array contains the column headers. The simple options are:</p>
55
- <p><strong>sorted_by:</strong> the column to sort by, it defaults to no sorting at all.
56
- <pre class="dawn">csv <span class="Keyword">=</span>&lt;&lt;-CSV
57
- Author,Best Book,Number of Pages,Style
58
- Samuel Beckett,Malone Muert,120,Modernism
59
- James Joyce,Ulysses,644,Modernism
60
- Nicholson Baker,Mezannine,150,Minimalism
61
- Vladimir Sorokin,The Queue,263,Satire
62
- CSV
63
-
64
- spreadsheet <span class="Keyword">=</span> <span class="Support">TableFu</span><span class="PunctuationSeparator">.</span><span class="Entity">new</span>(csv) <span class="Keyword">do </span><span class="PunctuationSeparator">|</span><span class="Variable">s</span><span class="PunctuationSeparator">|</span>
65
- s<span class="PunctuationSeparator">.</span><span class="Entity">sorted_by</span> <span class="Keyword">=</span> {'Best Book' <span class="PunctuationSeparator">=&gt;</span> {'order' <span class="PunctuationSeparator">=&gt;</span> 'ascending'}}
66
- <span class="Keyword">end</span>
67
- </pre><em>Returns:</em><pre class="dawn">[[&quot;Samuel Beckett&quot;<span class="PunctuationSeparator">,</span> &quot;Malone Muert&quot;<span class="PunctuationSeparator">,</span> &quot;120&quot;<span class="PunctuationSeparator">,</span> &quot;Modernism&quot;]<span class="PunctuationSeparator">,</span> [&quot;Nicholson Baker&quot;<span class="PunctuationSeparator">,</span> &quot;Mezannine&quot;<span class="PunctuationSeparator">,</span> &quot;150&quot;<span class="PunctuationSeparator">,</span> &quot;Minimalism&quot;]<span class="PunctuationSeparator">,</span> [&quot;Vladimir Sorokin&quot;<span class="PunctuationSeparator">,</span> &quot;The Queue&quot;<span class="PunctuationSeparator">,</span> &quot;263&quot;<span class="PunctuationSeparator">,</span> &quot;Satire&quot;]<span class="PunctuationSeparator">,</span> [&quot;James Joyce&quot;<span class="PunctuationSeparator">,</span> &quot;Ulysses&quot;<span class="PunctuationSeparator">,</span> &quot;644&quot;<span class="PunctuationSeparator">,</span> &quot;Modernism&quot;]]
68
- </pre>
69
- </p>
70
- <p><strong>columns:</strong> the columns to include in the table, useful when reordering and filtering extraneous columns. If no arguments are provided, <strong>TableFu</strong> will include all columns by default.
71
- <pre class="dawn">spreadsheet <span class="Keyword">=</span> <span class="Support">TableFu</span><span class="PunctuationSeparator">.</span><span class="Entity">new</span>(csv) <span class="Keyword">do </span><span class="PunctuationSeparator">|</span><span class="Variable">s</span><span class="PunctuationSeparator">|</span>
72
- s<span class="PunctuationSeparator">.</span><span class="Entity">columns</span> <span class="Keyword">=</span> [&quot;Best Book&quot;<span class="PunctuationSeparator">,</span> &quot;Author&quot;]
73
- <span class="Keyword">end</span>
74
-
75
- spreadsheet<span class="PunctuationSeparator">.</span><span class="Entity">columns</span><span class="PunctuationSeparator">.</span><span class="Entity">map</span> <span class="Keyword">do </span><span class="PunctuationSeparator">|</span><span class="Variable">column</span><span class="PunctuationSeparator">|</span>
76
- spreadsheet<span class="PunctuationSeparator">.</span><span class="Entity">rows</span>[<span class="Constant">0</span>]<span class="PunctuationSeparator">.</span><span class="Entity">column_for</span>(column)<span class="PunctuationSeparator">.</span><span class="Entity">to_s</span>
77
- <span class="Keyword">end</span>
78
- </pre><em>Returns:</em><pre class="dawn">[&quot;Malone Muert&quot;<span class="PunctuationSeparator">,</span> &quot;Samuel Beckett&quot;]
79
- </pre>
80
- Note that the columns are still accessible directly even if they're not in the columns array.
81
- <pre class="dawn">spreadsheet <span class="Keyword">=</span> <span class="Support">TableFu</span><span class="PunctuationSeparator">.</span><span class="Entity">new</span>(csv) <span class="Keyword">do </span><span class="PunctuationSeparator">|</span><span class="Variable">s</span><span class="PunctuationSeparator">|</span>
82
- s<span class="PunctuationSeparator">.</span><span class="Entity">columns</span> <span class="Keyword">=</span> [&quot;Best Book&quot;<span class="PunctuationSeparator">,</span> &quot;Author&quot;]
83
- <span class="Keyword">end</span>
84
-
85
- spreadsheet<span class="PunctuationSeparator">.</span><span class="Entity">rows</span>[<span class="Constant">0</span>]<span class="PunctuationSeparator">.</span><span class="Entity">column_for</span>('Style')<span class="PunctuationSeparator">.</span>to_s
86
- </pre><em>Returns:</em><pre class="dawn">&quot;Modernism&quot;
87
- </pre>
88
- </p>
89
-
90
- <h2><a id="macros" href="#toc">Macros / Formatting</a></h2>
91
- <p><strong>TableFu</strong> allows you to format columns of cells through the use of macros. See <a href="http://github.com/propublica/table-fu/blob/master/lib/table_fu/formatting.rb"><strong>TableFu::Formatting</strong></a> for the predefined macros available. </p>
92
- <p>The <strong>formatting</strong> attribute should be a hash of the form:
93
- <pre class="dawn">{&quot;Column Name&quot; <span class="PunctuationSeparator">=&gt;</span> 'Formatting Method Name'}
94
-
95
- <span class="Comment"><span class="Comment">#</span> or</span>
96
-
97
- {&quot;Meta Column Name&quot; <span class="PunctuationSeparator">=&gt;</span> {&quot;method&quot; <span class="PunctuationSeparator">=&gt;</span> &quot;Method Name&quot;<span class="PunctuationSeparator">,</span> &quot;arguments&quot; <span class="PunctuationSeparator">=&gt;</span> ['Column 1'<span class="PunctuationSeparator">,</span> 'Column 2' <span class="PunctuationSeparator">.</span><span class="PunctuationSeparator">.</span><span class="PunctuationSeparator">.</span> 'Column N']}}
98
-
99
- </pre>
100
- which will call the macro on the column name with the arguments if specified.
101
- </p>
102
- <p>For example, you can use the <strong>last_name</strong> formatter to extract the last name of a cell containing a person's name:
103
- <pre class="dawn">spreadsheet <span class="Keyword">=</span> <span class="Support">TableFu</span><span class="PunctuationSeparator">.</span><span class="Entity">new</span>(csv) <span class="Keyword">do </span><span class="PunctuationSeparator">|</span><span class="Variable">s</span><span class="PunctuationSeparator">|</span>
104
- s<span class="PunctuationSeparator">.</span><span class="Entity">formatting</span> <span class="Keyword">=</span> {&quot;Author&quot; <span class="PunctuationSeparator">=&gt;</span> 'last_name'}
105
- <span class="Keyword">end</span>
106
- spreadsheet<span class="PunctuationSeparator">.</span><span class="Entity">rows</span>[<span class="Constant">0</span>]<span class="PunctuationSeparator">.</span><span class="Entity">column_for</span>('Author')<span class="PunctuationSeparator">.</span>to_s
107
- </pre><em>Returns:</em><pre class="dawn">&quot;Beckett&quot;
108
- </pre>
109
- </p>
110
-
111
- <p>Of course, you can provide your own macros by patching <a href="http://github.com/propublica/table-fu/blob/master/lib/table_fu/formatting.rb">TableFu::Formatting</a>. <a href="http://www.github.com/propublica/table-setter">TableSetter</a> includes rails view helpers directly in <strong>TableFu::Formatting</strong>.
112
- <pre class="dawn"><span class="Keyword">class</span> <span class="Entity">TableFu::Formatting</span>
113
- <span class="Keyword">extend</span> <span class="Support">ActionView</span><span class="PunctuationSeparator">::</span><span class="Entity">Helpers</span><span class="PunctuationSeparator">::</span><span class="Entity">NumberHelper</span>
114
- <span class="Keyword">end</span>
115
- </pre>
116
- </p>
117
-
118
- <h2><a id="faceting" href="#toc">Faceting</a></h2>
119
- <p>Faceting provides a way to group rows together using a cell value they share in common. Calling <strong>TableFu#faceted_by</strong> returns an array of table fu instances each with a <strong>faceted_on</strong> attribute and with only the rows where that value appears.
120
- </p>
121
- <p>In this example there are 2 rows where "Modernism" appears in the style column, so calling <strong>faceted_on</strong> with the argument <strong>"Style"</strong> returns a <strong>TableFu</strong> instance with those rows grouped together:
122
- <pre class="dawn">spreadsheet <span class="Keyword">=</span> <span class="Support">TableFu</span><span class="PunctuationSeparator">.</span><span class="Entity">new</span>(csv)
123
- spreadsheet<span class="PunctuationSeparator">.</span><span class="Entity">faceted_by</span> &quot;Style&quot;
124
- </pre><em>Returns:</em><pre class="dawn">table<span class="PunctuationSeparator">.</span><span class="Entity">faceted_on</span> <span class="PunctuationSeparator">=&gt;</span> <span class="Variable">Minimalism</span><span class="PunctuationSeparator">,</span> table<span class="PunctuationSeparator">.</span><span class="Entity">rows</span> <span class="PunctuationSeparator">=&gt;</span> [[&quot;Nicholson Baker&quot;<span class="PunctuationSeparator">,</span> &quot;Mezannine&quot;<span class="PunctuationSeparator">,</span> &quot;150&quot;<span class="PunctuationSeparator">,</span> &quot;Minimalism&quot;]]
125
- table<span class="PunctuationSeparator">.</span><span class="Entity">faceted_on</span> <span class="PunctuationSeparator">=&gt;</span> <span class="Variable">Modernism</span><span class="PunctuationSeparator">,</span> table<span class="PunctuationSeparator">.</span><span class="Entity">rows</span> <span class="PunctuationSeparator">=&gt;</span> [[&quot;Samuel Beckett&quot;<span class="PunctuationSeparator">,</span> &quot;Malone Muert&quot;<span class="PunctuationSeparator">,</span> &quot;120&quot;<span class="PunctuationSeparator">,</span> &quot;Modernism&quot;]<span class="PunctuationSeparator">,</span> [&quot;James Joyce&quot;<span class="PunctuationSeparator">,</span> &quot;Ulysses&quot;<span class="PunctuationSeparator">,</span> &quot;644&quot;<span class="PunctuationSeparator">,</span> &quot;Modernism&quot;]]
126
- table<span class="PunctuationSeparator">.</span><span class="Entity">faceted_on</span> <span class="PunctuationSeparator">=&gt;</span> <span class="Variable">Satire</span><span class="PunctuationSeparator">,</span> table<span class="PunctuationSeparator">.</span><span class="Entity">rows</span> <span class="PunctuationSeparator">=&gt;</span> [[&quot;Vladimir Sorokin&quot;<span class="PunctuationSeparator">,</span> &quot;The Queue&quot;<span class="PunctuationSeparator">,</span> &quot;263&quot;<span class="PunctuationSeparator">,</span> &quot;Satire&quot;]]
127
- </pre>
128
- </p>
129
- <h2><a id="manipulation" href="#toc">Manipulation / Output</a></h2>
130
- <h3>Deleting Rows</h3>
131
- <p>In addition to hiding columns and faceting <strong>TableFu</strong> can delete rows from the csv. Let's get rid of James Joyce (no one ever finished <em>Ulysses</em> anyway):
132
- <pre class="dawn">spreadsheet <span class="Keyword">=</span> <span class="Support">TableFu</span><span class="PunctuationSeparator">.</span><span class="Entity">new</span>(csv) <span class="Keyword">do </span><span class="PunctuationSeparator">|</span><span class="Variable">s</span><span class="PunctuationSeparator">|</span>
133
- s<span class="PunctuationSeparator">.</span><span class="Entity">delete_rows!</span> [<span class="Constant">1</span>]
134
- <span class="Keyword">end</span>
135
- </pre><em>Returns:</em><pre class="dawn">[[&quot;Samuel Beckett&quot;<span class="PunctuationSeparator">,</span> &quot;Malone Muert&quot;<span class="PunctuationSeparator">,</span> &quot;120&quot;<span class="PunctuationSeparator">,</span> &quot;Modernism&quot;]<span class="PunctuationSeparator">,</span> [&quot;Nicholson Baker&quot;<span class="PunctuationSeparator">,</span> &quot;Mezannine&quot;<span class="PunctuationSeparator">,</span> &quot;150&quot;<span class="PunctuationSeparator">,</span> &quot;Minimalism&quot;]<span class="PunctuationSeparator">,</span> [&quot;Vladimir Sorokin&quot;<span class="PunctuationSeparator">,</span> &quot;The Queue&quot;<span class="PunctuationSeparator">,</span> &quot;263&quot;<span class="PunctuationSeparator">,</span> &quot;Satire&quot;]]
136
- </pre>
137
- The deleted rows are still available in <strong>@deleted_rows</strong> for later access:
138
- <pre class="dawn">spreadsheet <span class="Keyword">=</span> <span class="Support">TableFu</span><span class="PunctuationSeparator">.</span><span class="Entity">new</span>(csv) <span class="Keyword">do </span><span class="PunctuationSeparator">|</span><span class="Variable">s</span><span class="PunctuationSeparator">|</span>
139
- s<span class="PunctuationSeparator">.</span><span class="Entity">delete_rows!</span> [<span class="Constant">1</span>]
140
- <span class="Keyword">end</span>
141
- </pre><em>Returns:</em><pre class="dawn">table<span class="PunctuationSeparator">.</span><span class="Entity">deleted_rows</span> <span class="PunctuationSeparator">=&gt;</span> [[&quot;James Joyce&quot;<span class="PunctuationSeparator">,</span> &quot;Ulysses&quot;<span class="PunctuationSeparator">,</span> &quot;644&quot;<span class="PunctuationSeparator">,</span> &quot;Modernism&quot;]]
142
- </pre>
143
- </p>
144
- <h3>Pagination</h3>
145
- <p>If you want only a chunk of the data, say to paginate your table, you can call <strong>only!</strong> with the range of values you want to keep:
146
- <pre class="dawn">spreadsheet <span class="Keyword">=</span> <span class="Support">TableFu</span><span class="PunctuationSeparator">.</span><span class="Entity">new</span>(csv) <span class="Keyword">do </span><span class="PunctuationSeparator">|</span><span class="Variable">s</span><span class="PunctuationSeparator">|</span>
147
- s<span class="PunctuationSeparator">.</span><span class="Entity">sorted_by</span> <span class="Keyword">=</span> {'Style' <span class="PunctuationSeparator">=&gt;</span> {&quot;order&quot; <span class="PunctuationSeparator">=&gt;</span> 'ascending'}}
148
- <span class="Keyword">end</span>
149
-
150
- spreadsheet<span class="PunctuationSeparator">.</span><span class="Entity">only!</span>(<span class="Constant">2</span><span class="PunctuationSeparator">.</span><span class="PunctuationSeparator">.</span><span class="Constant">4</span>)
151
- spreadsheet<span class="PunctuationSeparator">.</span>rows
152
- </pre><em>Returns:</em><pre class="dawn">[[&quot;Nicholson Baker&quot;<span class="PunctuationSeparator">,</span> &quot;Mezannine&quot;<span class="PunctuationSeparator">,</span> &quot;150&quot;<span class="PunctuationSeparator">,</span> &quot;Minimalism&quot;]<span class="PunctuationSeparator">,</span> [&quot;Vladimir Sorokin&quot;<span class="PunctuationSeparator">,</span> &quot;The Queue&quot;<span class="PunctuationSeparator">,</span> &quot;263&quot;<span class="PunctuationSeparator">,</span> &quot;Satire&quot;]]
153
- </pre>
154
- </p>
155
- <h3>Sum</h3>
156
- <p>TableFu can also sum a column of values:
157
- <pre class="dawn">spreadsheet <span class="Keyword">=</span> <span class="Support">TableFu</span><span class="PunctuationSeparator">.</span><span class="Entity">new</span>(csv)
158
- spreadsheet<span class="PunctuationSeparator">.</span><span class="Entity">total_for</span>('Number of Pages')<span class="PunctuationSeparator">.</span>to_s
159
- </pre><em>Returns:</em><pre class="dawn"><span class="Constant">1177</span>
160
- </pre>
161
- </p>
162
- <h2><a id="links" href="#toc">Links</a></h2>
163
- <ul>
164
- <li><a href="http://github.com/propublica/table-setter">TableSetter</a><br>A Sinatra app that uses <strong>TableFu</strong> to render public Google Spreadsheets in custom HTML.</li>
165
- <li><a href="http://github.com/propublica/table-setter-generator">TableSetter Generator</a><br>
166
- A rails generator that allows you to create a rails app like TableSetter.
167
- </li>
168
- <li><a href="http://github.com/propublica/table-fu/issues">Issues</a><br>Post bug reports and feature requests here.</li>
169
- <li><a href="doc/index.html">API Docs</a></li>
170
- </ul>
171
- <h2><a id="credits" href="#toc">Credits</a></h2>
172
- <p><a href="http://github.com/thejefflarson">Jeff Larson</a> (Maintainer), <a href="http://github.com/brianboyer/">Brian Boyer</a>, <a href="http://github.com/kleinmatic">Scott Klein</a>, <a href="http://github.com/markpercival">Mark Percival</a>, and <a href="http://github.com/seebq">Charles Brian Quinn</a>.</p>
173
- <h2><a id="license" href="#toc">License</a></h2>
174
- <pre>Copyright (c) 2010 ProPublica
175
-
176
- Permission is hereby granted, free of charge, to any person obtaining
177
- a copy of this software and associated documentation files (the
178
- "Software"), to deal in the Software without restriction, including
179
- without limitation the rights to use, copy, modify, merge, publish,
180
- distribute, sublicense, and/or sell copies of the Software, and to
181
- permit persons to whom the Software is furnished to do so, subject to
182
- the following conditions:
183
-
184
- The above copyright notice and this permission notice shall be
185
- included in all copies or substantial portions of the Software.
186
-
187
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
188
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
189
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
190
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
191
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
192
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
193
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
194
- </pre>
195
- </body>
196
- </html>
data/lib/table_fu.rb CHANGED
@@ -62,7 +62,7 @@ class TableFu
62
62
  all_rows = []
63
63
  @table.each_with_index do |row, index|
64
64
  all_rows << TableFu::Row.new(row, index, self)
65
- end
65
+ end
66
66
  all_rows.sort
67
67
  end
68
68
 
@@ -210,6 +210,15 @@ class TableFu
210
210
  end
211
211
  alias_method :column_for, :datum_for
212
212
 
213
+ # sugar
214
+ def [](col)
215
+ if col.is_a?(String)
216
+ column_for(col)
217
+ else
218
+ super(col)
219
+ end
220
+ end
221
+
213
222
  # Comparator for sorting a spreadsheet row.
214
223
  #
215
224
  def <=>(b)
@@ -96,6 +96,11 @@ describe TableFu, 'with a complicated setup' do
96
96
  @spreadsheet.rows[0].column_for('State').to_s.should eql "Wyoming"
97
97
  end
98
98
 
99
+ it 'should have some sugar' do
100
+ @spreadsheet.rows[3]['State'].to_s.should eql "Georgia"
101
+
102
+ end
103
+
99
104
  it 'should total a column' do
100
105
  @spreadsheet.total_for("Total Appropriation").value.should eql 16640189309
101
106
  @spreadsheet.total_for("Total Appropriation").to_s.should eql "$16,640,189,309"
data/table_fu.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{table_fu}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
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"]
12
- s.date = %q{2010-05-13}
12
+ s.date = %q{2010-05-26}
13
13
  s.description = %q{A library for manipulating tables as arrays}
14
14
  s.email = %q{jeff.larson@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -72,7 +72,7 @@ Gem::Specification.new do |s|
72
72
  s.homepage = %q{http://propublica.github.com/table-fu/}
73
73
  s.rdoc_options = ["--charset=UTF-8"]
74
74
  s.require_paths = ["lib"]
75
- s.rubygems_version = %q{1.3.6}
75
+ s.rubygems_version = %q{1.3.7}
76
76
  s.summary = %q{TableFu makes arrays act like spreadsheets}
77
77
  s.test_files = [
78
78
  "spec/readme_example_spec.rb",
@@ -95,7 +95,7 @@ Gem::Specification.new do |s|
95
95
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
96
96
  s.specification_version = 3
97
97
 
98
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
98
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
99
99
  s.add_runtime_dependency(%q<fastercsv>, [">= 0"])
100
100
  s.add_development_dependency(%q<spec>, [">= 0"])
101
101
  else
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_fu
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Mark Percival
@@ -15,16 +16,18 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-05-13 00:00:00 -04:00
19
+ date: 2010-05-26 00:00:00 -04:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: fastercsv
23
24
  prerelease: false
24
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
25
27
  requirements:
26
28
  - - ">="
27
29
  - !ruby/object:Gem::Version
30
+ hash: 3
28
31
  segments:
29
32
  - 0
30
33
  version: "0"
@@ -34,9 +37,11 @@ dependencies:
34
37
  name: spec
35
38
  prerelease: false
36
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
37
41
  requirements:
38
42
  - - ">="
39
43
  - !ruby/object:Gem::Version
44
+ hash: 3
40
45
  segments:
41
46
  - 0
42
47
  version: "0"
@@ -113,23 +118,27 @@ rdoc_options:
113
118
  require_paths:
114
119
  - lib
115
120
  required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
116
122
  requirements:
117
123
  - - ">="
118
124
  - !ruby/object:Gem::Version
125
+ hash: 3
119
126
  segments:
120
127
  - 0
121
128
  version: "0"
122
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
123
131
  requirements:
124
132
  - - ">="
125
133
  - !ruby/object:Gem::Version
134
+ hash: 3
126
135
  segments:
127
136
  - 0
128
137
  version: "0"
129
138
  requirements: []
130
139
 
131
140
  rubyforge_project:
132
- rubygems_version: 1.3.6
141
+ rubygems_version: 1.3.7
133
142
  signing_key:
134
143
  specification_version: 3
135
144
  summary: TableFu makes arrays act like spreadsheets