Skip to content

Implemented EXP, INT, and MONTH functions #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ GEM
remote: http://rubygems.org/
specs:
ZenTest (4.6.2)
active_support (3.0.0)
activesupport (= 3.0.0)
activesupport (3.0.0)
diff-lcs (1.1.3)
ffi (1.0.11)
nokogiri (1.5.0)
Expand All @@ -13,12 +16,17 @@ GEM
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)
rubypeg (0.0.4)
rubyscriptwriter
rubyscriptwriter (0.0.2)

PLATFORMS
ruby

DEPENDENCIES
ZenTest
active_support
ffi
nokogiri
rspec
rubypeg
25 changes: 25 additions & 0 deletions spec/excel/excel_functions/or_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require_relative '../../spec_helper.rb'

describe "ExcelFunctions: OR" do

it "should return something when given appropriate arguments" do
FunctionTest.or(1).should == 1
end

it "should return an error when given inappropriate arguments" do
FunctionTest.or("Asdasddf").should == :value
end

it "should treat nil as zero" do
FunctionTest.or(nil).should == 0
end

it "should return an error if an argument is an error" do
FunctionTest.or(:error).should == :error
end

it "should be in the list of functions that can be mapped to ruby" do
MapFormulaeToRuby::FUNCTIONS['OR'].should == 'or'
end

end
25 changes: 25 additions & 0 deletions spec/excel/excel_functions/today_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require_relative '../../spec_helper.rb'

describe "ExcelFunctions: TODAY" do

it "should return something when given appropriate arguments" do
FunctionTest.today(1).should == 1
end

it "should return an error when given inappropriate arguments" do
FunctionTest.today("Asdasddf").should == :value
end

it "should treat nil as zero" do
FunctionTest.today(nil).should == 0
end

it "should return an error if an argument is an error" do
FunctionTest.today(:error).should == :error
end

it "should be in the list of functions that can be mapped to ruby" do
MapFormulaeToRuby::FUNCTIONS['TODAY'].should == 'today'
end

end
9 changes: 9 additions & 0 deletions src/compile/ruby/map_formulae_to_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class MapFormulaeToRuby < MapValuesToRuby
'MAX' => 'max',
'MIN' => 'min',
'MOD' => 'mod',
<<<<<<< HEAD
<<<<<<< HEAD
'MONTH' => 'month',
'OR' => 'excel_or',
=======
>>>>>>> parent of d46088e... Implemented EXP, INT, and MONTH functions
=======
>>>>>>> parent of d46088e... Implemented EXP, INT, and MONTH functions
'PI' => 'pi',
'PMT' => 'pmt',
'ROUND' => 'round',
Expand All @@ -42,6 +50,7 @@ class MapFormulaeToRuby < MapValuesToRuby
'SUMIF' => 'sumif',
'SUMIFS' => 'sumifs',
'SUMPRODUCT' => 'sumproduct',
'TODAY' => 'today',
'VLOOKUP' => 'vlookup',
'^' => 'power'
}
Expand Down
16 changes: 16 additions & 0 deletions src/excel/excel_functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,19 @@ module ExcelFunctions
require_relative 'excel_functions/rounddown'

require_relative 'excel_functions/negative'
<<<<<<< HEAD
<<<<<<< HEAD

require_relative 'excel_functions/exp'

require_relative 'excel_functions/int'

require_relative 'excel_functions/month'

require_relative 'excel_functions/excel_or'

require_relative 'excel_functions/today'
=======
>>>>>>> parent of d46088e... Implemented EXP, INT, and MONTH functions
=======
>>>>>>> parent of d46088e... Implemented EXP, INT, and MONTH functions
2 changes: 1 addition & 1 deletion src/excel/excel_functions/excel_equal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def excel_equal?(a,b)

case a
when String
a.downcase == b.downcase
a.to_s.downcase == b.to_s.downcase
else
a == b
end
Expand Down
12 changes: 12 additions & 0 deletions src/excel/excel_functions/excel_or.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module ExcelFunctions

def excel_or(*args)

args.each do |argument|
return true if argument
end

return false
end

end
7 changes: 7 additions & 0 deletions src/excel/excel_functions/today.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ExcelFunctions

def today
return Time.now.strftime("%m/%d/%y")
end

end