rubyexcel 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyexcel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: