Module: Soroban
- Defined in:
- lib/soroban/cell.rb,
lib/soroban/sheet.rb,
lib/soroban/error.rb,
lib/soroban/parser.rb,
lib/soroban/helpers.rb,
lib/soroban/tabulator.rb,
lib/soroban/functions.rb,
lib/soroban/value_walker.rb,
lib/soroban/label_walker.rb
Defined Under Namespace
Classes: Cell, LabelWalker, ParseError, RangeError, RecursionError, Sheet, Tabulator, UndefinedError, ValueWalker
Class Method Summary (collapse)
-
+ (Boolean) boolean?(data)
Return true if the supplied data is a boolean.
-
+ (Object) call(sheet, name, *args)
Call the named function within the context of the specified sheet.
-
+ (Object) define(function_hash)
Define a new function.
-
+ (Boolean) formula?(data)
Return true if the supplied data represents a formula.
-
+ (Object) functions
Return an array of all defined functions.
-
+ (Object) getPos(label)
Return the row and column index of the given label.
-
+ (Object) getRange(range)
Return the components of a range.
-
+ (Object) getValues(context, *args)
Return an array of values for the supplied arguments (which may be numbers, labels and ranges).
-
+ (Boolean) number?(data)
Return true if the supplied data is a number.
-
+ (Object) parser
A Treetop parser for Excel formulas that can generate valid Ruby expression via a rewrite operation, and which can build an array of referenced labels.
-
+ (Boolean) range?(data)
Return true if the supplied data is a range.
-
+ (Boolean) string?(data)
Return true if the supplied data is a string.
-
+ (Boolean) unknown?(data)
Return true if the supplied data is of no recognised format.
Class Method Details
+ (Boolean) boolean?(data)
Return true if the supplied data is a boolean.
16 17 18 |
# File 'lib/soroban/helpers.rb', line 16 def self.boolean?(data) /^(true|false)$/i.match(data.to_s) && true || false end |
+ (Object) call(sheet, name, *args)
Call the named function within the context of the specified sheet.
15 16 17 18 19 |
# File 'lib/soroban/functions.rb', line 15 def self.call(sheet, name, *args) function = name.upcase.to_sym raise Soroban::UndefinedError, "No such function '#{function}'" unless @@functions[function] sheet.instance_exec(*args, &@@functions[function]) end |
+ (Object) define(function_hash)
Define a new function.
4 5 6 7 |
# File 'lib/soroban/functions.rb', line 4 def self.define(function_hash) @@functions ||= {} function_hash.each { |name, callback| @@functions[name] = callback } end |
+ (Boolean) formula?(data)
Return true if the supplied data represents a formula.
6 7 8 |
# File 'lib/soroban/helpers.rb', line 6 def self.formula?(data) data.to_s.slice(0..0) == '=' end |
+ (Object) functions
Return an array of all defined functions.
10 11 12 |
# File 'lib/soroban/functions.rb', line 10 def self.functions @@functions.keys.map { |f| f.to_s } end |
+ (Object) getPos(label)
Return the row and column index of the given label.
41 42 43 44 45 |
# File 'lib/soroban/helpers.rb', line 41 def self.getPos(label) # TODO: fix for labels such as "BC42" match = /^([a-zA-Z]+)([\d]+)$/.match(label.to_s) return match[2].to_i - 1, match[1].upcase[0].ord-"A"[0].ord end |
+ (Object) getRange(range)
Return the components of a range.
36 37 38 |
# File 'lib/soroban/helpers.rb', line 36 def self.getRange(range) /^([a-zA-Z]+)([\d]+):([a-zA-Z]+)([\d]+)$/.match(range.to_s).to_a[1..-1] end |
+ (Object) getValues(context, *args)
Return an array of values for the supplied arguments (which may be numbers, labels and ranges).
48 49 50 |
# File 'lib/soroban/helpers.rb', line 48 def self.getValues(context, *args) args.map { |arg| Soroban::range?(arg) ? ValueWalker.new(arg, context).to_a : arg }.to_a.flatten end |
+ (Boolean) number?(data)
Return true if the supplied data is a number.
11 12 13 |
# File 'lib/soroban/helpers.rb', line 11 def self.number?(data) Float(data.to_s) && true rescue false end |
+ (Object) parser
A Treetop parser for Excel formulas that can generate valid Ruby expression via a rewrite operation, and which can build an array of referenced labels.
11 12 13 |
# File 'lib/soroban/parser.rb', line 11 def self.parser @@parser ||= SorobanParser.new end |
+ (Boolean) range?(data)
Return true if the supplied data is a range.
26 27 28 |
# File 'lib/soroban/helpers.rb', line 26 def self.range?(data) /^([a-zA-Z]+)([\d]+):([a-zA-Z]+)([\d]+)$/.match(data.to_s) && true || false end |
+ (Boolean) string?(data)
Return true if the supplied data is a string.
21 22 23 |
# File 'lib/soroban/helpers.rb', line 21 def self.string?(data) /^["](\"|[^"])*["]$/.match(data.to_s) && true || /^['][^']*[']$/.match(data.to_s) && true || false end |
+ (Boolean) unknown?(data)
Return true if the supplied data is of no recognised format.
31 32 33 |
# File 'lib/soroban/helpers.rb', line 31 def self.unknown?(data) !self.formula?(data) && !self.number?(data) && !self.boolean?(data) && !self.string?(data) end |