Class: Soroban::Cell
- Inherits:
-
Object
- Object
- Soroban::Cell
- Defined in:
- lib/soroban/cell.rb
Overview
Represents a single cell in a sheet. This class is used internally, and isn’t exposed to the caller. The cell stores the original string representation of its contents, and the executable Ruby version of same, as generated via a rewrite grammar. Cells also store their dependencies.
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#excel ⇒ Object
readonly
Returns the value of attribute excel.
-
#ruby ⇒ Object
readonly
Returns the value of attribute ruby.
Instance Method Summary collapse
-
#get ⇒ Object
Eval the Ruby version of the string contents within the context of the owning sheet.
-
#initialize(binding) ⇒ Cell
constructor
Cells are initialised with a binding to allow formulas to be executed within the context of the sheet which ownes the cell.
-
#set(contents) ⇒ Object
Set the contents of a cell, and store the executable Ruby version.
Constructor Details
#initialize(binding) ⇒ Cell
Cells are initialised with a binding to allow formulas to be executed within the context of the sheet which ownes the cell.
14 15 16 17 18 |
# File 'lib/soroban/cell.rb', line 14 def initialize(binding) @dependencies = [] @binding = binding @touched = false end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
10 11 12 |
# File 'lib/soroban/cell.rb', line 10 def dependencies @dependencies end |
#excel ⇒ Object (readonly)
Returns the value of attribute excel.
10 11 12 |
# File 'lib/soroban/cell.rb', line 10 def excel @excel end |
#ruby ⇒ Object (readonly)
Returns the value of attribute ruby.
10 11 12 |
# File 'lib/soroban/cell.rb', line 10 def ruby @ruby end |
Instance Method Details
#get ⇒ Object
Eval the Ruby version of the string contents within the context of the owning sheet. Will throw Soroban::RecursionError if recursion is detected.
29 30 31 32 33 34 35 |
# File 'lib/soroban/cell.rb', line 29 def get raise Soroban::RecursionError, "Loop detected when evaluating '#{@excel}'" if @touched @touched = true eval(@ruby, @binding) ensure @touched = false end |