rubyexcel 0.1.7 → 0.1.8
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.
- data/lib/rubyexcel/section.rb +4 -0
- data/lib/rubyexcel/sheet.rb +23 -0
- metadata +1 -1
data/lib/rubyexcel/section.rb
CHANGED
@@ -201,7 +201,9 @@ module RubyExcel
|
|
201
201
|
|
202
202
|
class Row < Section
|
203
203
|
|
204
|
+
# The Row number
|
204
205
|
attr_reader :idx
|
206
|
+
alias index idx
|
205
207
|
|
206
208
|
#
|
207
209
|
# Creates a RubyExcel::Row instance
|
@@ -296,7 +298,9 @@ module RubyExcel
|
|
296
298
|
|
297
299
|
class Column < Section
|
298
300
|
|
301
|
+
# The Column letter
|
299
302
|
attr_reader :idx
|
303
|
+
alias index idx
|
300
304
|
|
301
305
|
#
|
302
306
|
# Creates a RubyExcel::Column instance
|
data/lib/rubyexcel/sheet.rb
CHANGED
@@ -132,6 +132,29 @@ module RubyExcel
|
|
132
132
|
data.advanced_filter!( *args ); self
|
133
133
|
end
|
134
134
|
|
135
|
+
#
|
136
|
+
# Average the values in a Column by searching another Column
|
137
|
+
#
|
138
|
+
# @param [String] find_header the header of the Column to yield to the block
|
139
|
+
# @param [String] avg_header the header of the Column to average
|
140
|
+
# @yield yields the find_header column values to the block
|
141
|
+
#
|
142
|
+
|
143
|
+
def averageif( find_header, avg_header )
|
144
|
+
return to_enum( :sumif ) unless block_given?
|
145
|
+
find_col, avg_col = ch( find_header ), ch( avg_header )
|
146
|
+
sum = find_col.each_cell_wh.inject([0,0]) do |sum,ce|
|
147
|
+
if yield( ce.value )
|
148
|
+
sum[0] += avg_col[ ce.row ]
|
149
|
+
sum[1] += 1
|
150
|
+
sum
|
151
|
+
else
|
152
|
+
sum
|
153
|
+
end
|
154
|
+
end
|
155
|
+
sum.first.to_f / sum.last
|
156
|
+
end
|
157
|
+
|
135
158
|
#
|
136
159
|
# Access an Cell by indices.
|
137
160
|
#
|