rubyfromexcel 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -172,6 +172,7 @@ module RubyFromExcel
172
172
  excel_function :round
173
173
  excel_function :roundup
174
174
  excel_function :rounddown
175
+ excel_function :mod
175
176
 
176
177
  def standard_function(name_to_use_in_ruby,args)
177
178
  "#{name_to_use_in_ruby}(#{args.map {|a| a.visit(self) }.join(',')})"
@@ -126,6 +126,14 @@ module RubyFromExcel
126
126
  return :na unless decimal_places.is_a?(Numeric)
127
127
  (number * 10**decimal_places).floor.to_f / 10**decimal_places
128
128
  end
129
+
130
+ def mod(number,divisor)
131
+ return number if iserr(number)
132
+ return divisor if iserr(divisor)
133
+ return :na unless number.is_a?(Numeric)
134
+ return :na unless divisor.is_a?(Numeric)
135
+ number % divisor
136
+ end
129
137
 
130
138
  def sum(*args)
131
139
  flatten_and_inject(args) do |counter,arg|
@@ -53,6 +53,14 @@ describe "rounddown" do
53
53
  end
54
54
  end
55
55
 
56
+ describe "mod" do
57
+ it "should return the remainder of a number" do
58
+ FunctionTest.mod(10,3).should == 1.0
59
+ FunctionTest.mod(10,5).should == 0.0
60
+ FunctionTest.mod(1.1,1).should be_close(0.1,0.01)
61
+ end
62
+ end
63
+
56
64
  describe "sum" do
57
65
  it "should total areas correctly" do
58
66
  FunctionTest.sum(1,2,3).should == 6
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Thomas Counsell, Green on Black Ltd