Module: ArelExtensions::MathFunctions
- Included in:
- Attributes
- Defined in:
- lib/arel_extensions/math_functions.rb
Instance Method Summary collapse
-
#abs ⇒ Object
Abs function returns the absolute value of a number passed as argument #.
-
#ceil ⇒ Object
will rounded up any positive or negative decimal value within the function upwards #.
-
#floor ⇒ Object
function rounded up any positive or negative decimal value down to the next least integer.
-
#format_number(format_string, locale = nil) ⇒ Object
function returning a number at a specific format.
-
#log10 ⇒ Object
function gives the base 10 log.
-
#pow(exposant = 0) ⇒ Object
function gives the power of a number.
-
#power(exposant = 0) ⇒ Object
function gives the power of a number.
-
#round(precision = nil) ⇒ Object
function is used to round a numeric field to the number of decimals specified.
-
#std(unbiased = true) ⇒ Object
Aggregate Functions.
- #variance(unbiased = true) ⇒ Object
Instance Method Details
#abs ⇒ Object
Abs function returns the absolute value of a number passed as argument #
15 16 17 |
# File 'lib/arel_extensions/math_functions.rb', line 15 def abs ArelExtensions::Nodes::Abs.new [self] end |
#ceil ⇒ Object
will rounded up any positive or negative decimal value within the function upwards #
20 21 22 |
# File 'lib/arel_extensions/math_functions.rb', line 20 def ceil ArelExtensions::Nodes::Ceil.new [self] end |
#floor ⇒ Object
function rounded up any positive or negative decimal value down to the next least integer
25 26 27 |
# File 'lib/arel_extensions/math_functions.rb', line 25 def floor ArelExtensions::Nodes::Floor.new [self] end |
#format_number(format_string, locale = nil) ⇒ Object
function returning a number at a specific format
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/arel_extensions/math_functions.rb', line 70 def format_number format_string, locale=nil begin sprintf(format_string,0) # this line is to get the right error message if the format_string is not correct m = /^(.*)%([ #+\-0]*)([1-9][0-9]+|[1-9]?)[.]?([0-9]*)([a-zA-Z])(.*)$/.match(format_string) opts = { :prefix => m[1], :flags => m[2].split(//).uniq.join, :width => m[3].to_i, :precision => m[4] != '' ? m[4].to_i : 6, :type => m[5], :suffix => m[6], :locale => locale, :original_string => format_string } # opts = {:locale => 'fr_FR', :type => "e"/"f"/"d", :prefix => "$ ", :suffix => " %", :flags => " +-#0", :width => 5, :precision => 6} ArelExtensions::Nodes::FormattedNumber.new [self,opts] rescue Exception Arel::Nodes.build_quoted('Wrong Format') end end |
#log10 ⇒ Object
function gives the base 10 log
30 31 32 |
# File 'lib/arel_extensions/math_functions.rb', line 30 def log10 ArelExtensions::Nodes::Log10.new [self] end |
#pow(exposant = 0) ⇒ Object
function gives the power of a number
35 36 37 |
# File 'lib/arel_extensions/math_functions.rb', line 35 def pow exposant = 0 ArelExtensions::Nodes::Power.new [self,exposant] end |
#power(exposant = 0) ⇒ Object
function gives the power of a number
40 41 42 |
# File 'lib/arel_extensions/math_functions.rb', line 40 def power exposant = 0 ArelExtensions::Nodes::Power.new [self,exposant] end |
#round(precision = nil) ⇒ Object
function is used to round a numeric field to the number of decimals specified
61 62 63 64 65 66 67 |
# File 'lib/arel_extensions/math_functions.rb', line 61 def round precision = nil if precision ArelExtensions::Nodes::Round.new [self, precision] else ArelExtensions::Nodes::Round.new [self] end end |
#std(unbiased = true) ⇒ Object
Aggregate Functions
45 46 47 |
# File 'lib/arel_extensions/math_functions.rb', line 45 def std unbiased = true ArelExtensions::Nodes::Std.new [self,unbiased] end |
#variance(unbiased = true) ⇒ Object
49 50 51 |
# File 'lib/arel_extensions/math_functions.rb', line 49 def variance unbiased = true ArelExtensions::Nodes::Variance.new [self,unbiased] end |