lib/formulae/run/excel_functions.rb in rubyfromexcel-0.0.7 vs lib/formulae/run/excel_functions.rb in rubyfromexcel-0.0.9
- old
+ new
@@ -132,10 +132,14 @@
return divisor if iserr(divisor)
return :na unless number.is_a?(Numeric)
return :na unless divisor.is_a?(Numeric)
number % divisor
end
+
+ def pmt(rate,periods,principal)
+ -principal*(rate*((1+rate)**periods))/(((1+rate)**periods)-1)
+ end
def sum(*args)
flatten_and_inject(args) do |counter,arg|
arg.is_a?(Numeric) ? counter + arg.to_f : counter
end
@@ -206,13 +210,15 @@
end
def max(*args)
args = args.map { |arg| arg.respond_to?(:to_a) ? arg.to_a : arg }
args.flatten!
+ if (error = args.find { |arg| iserr(arg) })
+ return error
+ end
args.delete_if { |arg| !arg.kind_of?(Numeric) }
args.delete_if { |arg| arg.kind_of?(Empty) }
- return error if error = args.find { |arg| iserr(arg) }
args.max
end
def abs(value)
return value if iserr(value)
@@ -342,14 +348,15 @@
:ref
end
def iserr(arg)
return true if arg.is_a? Symbol
- return true if arg.is_a?(Float) && arg.nan?
+ return true if arg.respond_to?(:nan?) && arg.nan?
+ return true if arg.respond_to?(:infinite?) && arg.infinite?
false
end
- def excel_if(condition,true_value,false_value)
+ def excel_if(condition,true_value,false_value = false)
condition ? true_value : false_value
end
def iferror(value,value_if_error)
iserr(value) ? value_if_error : value
\ No newline at end of file