Class: RubyFromExcel::FunctionCompiler
- Inherits:
-
Object
- Object
- RubyFromExcel::FunctionCompiler
- Includes:
- ExcelFunctions
- Defined in:
- lib/formulae/compile/formula_builder.rb
Instance Attribute Summary collapse
-
#worksheet ⇒ Object
Returns the value of attribute worksheet.
Instance Method Summary collapse
- #find_or_create_worksheet(worksheet_name) ⇒ Object
-
#initialize(worksheet) ⇒ FunctionCompiler
constructor
A new instance of FunctionCompiler.
- #method_missing(method, *arguments, &block) ⇒ Object
- #to_s ⇒ Object
Methods included from ExcelFunctions
#a, #abs, #average, #c, #calculate_index_formula, #calculate_match, #choose, #count, #counta, #countif, #countifs, #excel_and, #excel_comparison, #excel_if, #excel_or, #find, #flatten_and_inject, #formula_cache, #iferror, #index, #indirect, #iserr, #left, #m, #match, #max, #min, #mod, #na, #npv, #pmt, #r, #recalculate, #ref, #result_cache, #round, #rounddown, #roundup, #s, #set, #subtotal, #sum, #sumif, #sumifs, #sumproduct, #t, #text, #variable_name
Constructor Details
#initialize(worksheet) ⇒ FunctionCompiler
Returns a new instance of FunctionCompiler.
20 21 22 |
# File 'lib/formulae/compile/formula_builder.rb', line 20 def initialize(worksheet) self.worksheet = worksheet end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/formulae/compile/formula_builder.rb', line 24 def method_missing(method,*arguments, &block) return super unless arguments.empty? return super unless block == nil return find_or_create_worksheet(method.to_s) if method.to_s =~ /sheet\d+/ return super unless method.to_s =~ /[a-z]+\d+/ cell = worksheet.cell(method.to_s) return 0.0.extend(Empty) unless cell raise DependsOnCalculatedFormulaError.new unless cell.can_be_replaced_with_value? cell.value_for_including end |
Instance Attribute Details
#worksheet ⇒ Object
Returns the value of attribute worksheet.
18 19 20 |
# File 'lib/formulae/compile/formula_builder.rb', line 18 def worksheet @worksheet end |
Instance Method Details
#find_or_create_worksheet(worksheet_name) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/formulae/compile/formula_builder.rb', line 35 def find_or_create_worksheet(worksheet_name) @worksheets ||= {} return @worksheets[worksheet_name] if @worksheets.has_key?(worksheet_name) new_worksheet = FunctionCompiler.new(worksheet.workbooks.worksheets[worksheet_name]) @worksheets[worksheet_name] = new_worksheet new_worksheet end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/formulae/compile/formula_builder.rb', line 43 def to_s worksheet.to_s end |