Class: Formula

Inherits:
Object
  • Object
show all
Defined in:
lib/surpass/formula.rb

Constant Summary collapse

NO_CALCS =
0x00
RECALC_ALWAYS =
0x01
CALC_ON_OPEN =
0x02
PART_OF_SHARED_FORMULA =
0x08

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formula_string) ⇒ Formula

Returns a new instance of Formula.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/surpass/formula.rb', line 9

def initialize(formula_string)
  raise "formulas not available" unless FORMULAS_AVAILABLE
  @lexer = ExcelFormula::Lexer.new(formula_string)
#    puts @lexer.inspect
  @parser = ExcelFormula::Parser.new(@lexer)
  begin
    @parser.formula
  rescue RuntimeError => e
    puts e
    raise "invalid Excel formula"
  end
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



7
8
9
# File 'lib/surpass/formula.rb', line 7

def parser
  @parser
end

Instance Method Details

#to_biffObject



22
23
24
25
# File 'lib/surpass/formula.rb', line 22

def to_biff
  rpn = @parser.rpn
  [rpn.length].pack('v') + rpn
end