ar_result_calculations 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,10 +3,17 @@ h1. Description
3
3
  p. ar_result_calculations adds methods to Array for when Array is an ActiveRecord result set. For example:
4
4
 
5
5
  bc. Product.all.sum(:price)
6
- Product.all.average(:price)
6
+
7
+ p. Will return the sum of the attribute :price from all rows in the result set. Note this is not the same as Product.sum(:price) which will create an SQL statement that does the summing. When possible the ActiveRecord call which uses SQL will be more efficient if the result set has not already been returned.
8
+
9
+ bc. Product.all.average(:price)
7
10
  Product.all.regression(:sales_volumn)
8
11
 
9
- p. Will return the sum of the attribute :price from all rows. Note this is not the same as Product.sum(:price) which will create an SQL statement that does the summing.
12
+ p. Will calculate the average and regression of the specified columns.
13
+
14
+ bc. Product.all(:select => '(price * 2) as double_price').make_numeric(:double_price).sum(:double_price)
15
+
16
+ p. Will return the sum of the derived column 'double_price'. Note the call to **make_numeric** which is will coerce the derived column into numbers that can then be summed. ActiveRecord returns derived columns as strings hence the required coercion.
10
17
 
11
18
  h2. Methods created on Array
12
19
 
@@ -18,9 +25,9 @@ p. All methods take one parameter (column name).
18
25
  |count|Count the given column. Delegates to super() if not an AR result set|
19
26
  |min|Min the given column. Delegates to super() if not an AR result set|
20
27
  |max|Max the given column. Delegates to super() if not an AR result set|
21
- |regression|Ordinary Least Squares regression on the given column. Returns the regression as an array|
22
- |slope|Returns the slope of a regression on a given column|
23
- |make_numeric_|Coerces a column to be numeric. Useful if you have derived columns returned from a query that are not in the model definition and hence are otherwise returned as strings. Returns **self** so is composable|
28
+ |regression|Ordinary Least Squares regression on the given column. Returns the regression as an array. Argument should be either an ActiveRecord result set or an array of numbers|
29
+ |slope|Returns the slope of a regression on a given column. Argument should be either an ActiveRecord result set or an array of numbers|
30
+ |make_numeric|Coerces a column to be numeric. Useful if you have derived columns returned from a query that are not in the model definition and hence are otherwise returned as strings. Returns **self** so is composable|
24
31
 
25
32
  h1. License
26
33
 
@@ -1,3 +1,3 @@
1
1
  module ArResultCalculations
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_result_calculations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kip Cole