diff --git a/Gemfile.lock b/Gemfile.lock index 1916f71..90634d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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 diff --git a/spec/excel/excel_functions/or_spec.rb b/spec/excel/excel_functions/or_spec.rb new file mode 100644 index 0000000..5066929 --- /dev/null +++ b/spec/excel/excel_functions/or_spec.rb @@ -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 diff --git a/spec/excel/excel_functions/today_spec.rb b/spec/excel/excel_functions/today_spec.rb new file mode 100644 index 0000000..323793b --- /dev/null +++ b/spec/excel/excel_functions/today_spec.rb @@ -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 diff --git a/src/compile/ruby/map_formulae_to_ruby.rb b/src/compile/ruby/map_formulae_to_ruby.rb index 5c050fd..d700c48 100644 --- a/src/compile/ruby/map_formulae_to_ruby.rb +++ b/src/compile/ruby/map_formulae_to_ruby.rb @@ -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', @@ -42,6 +50,7 @@ class MapFormulaeToRuby < MapValuesToRuby 'SUMIF' => 'sumif', 'SUMIFS' => 'sumifs', 'SUMPRODUCT' => 'sumproduct', + 'TODAY' => 'today', 'VLOOKUP' => 'vlookup', '^' => 'power' } diff --git a/src/excel/excel_functions.rb b/src/excel/excel_functions.rb index c49f8d5..494d22b 100644 --- a/src/excel/excel_functions.rb +++ b/src/excel/excel_functions.rb @@ -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 diff --git a/src/excel/excel_functions/excel_equal.rb b/src/excel/excel_functions/excel_equal.rb index 5ffac3a..d10ff73 100644 --- a/src/excel/excel_functions/excel_equal.rb +++ b/src/excel/excel_functions/excel_equal.rb @@ -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 diff --git a/src/excel/excel_functions/excel_or.rb b/src/excel/excel_functions/excel_or.rb new file mode 100644 index 0000000..9cdf1be --- /dev/null +++ b/src/excel/excel_functions/excel_or.rb @@ -0,0 +1,12 @@ +module ExcelFunctions + + def excel_or(*args) + + args.each do |argument| + return true if argument + end + + return false + end + +end diff --git a/src/excel/excel_functions/today.rb b/src/excel/excel_functions/today.rb new file mode 100644 index 0000000..81f3531 --- /dev/null +++ b/src/excel/excel_functions/today.rb @@ -0,0 +1,7 @@ +module ExcelFunctions + + def today + return Time.now.strftime("%m/%d/%y") + end + +end