class Soroban::Helpers
Public Class Methods
Return true if the supplied data is a boolean.
# File lib/soroban/helpers.rb, line 18 def self.boolean?(data) /^(true|false)$/i.match(data.to_s) && true || false end
Return true if the supplied data represents a formula.
# File lib/soroban/helpers.rb, line 8 def self.formula?(data) data.to_s.slice(0..0) == '=' end
Return the row and column index of the given label. This converts something like “B42” into [41, 1]. It is a known bug that it does not work for labels of the form “BC42”. Will raise a ParseError
if the supplied argument is not a valid label.
# File lib/soroban/helpers.rb, line 64 def self.getPos(data) raise Soroban::ParseError, "invalid #getPos for '#{data}'" if !label?(data) match = /^([a-zA-Z]+)([\d]+)$/.match(data.to_s) return [match[2].to_i - 1, match[1].upcase[0].ord-"A"[0].ord] end
Return the components of a range. This converts something like “A12:C42” to a tuple of the form [“A”, “12”, “C”, “42”]. Will raise a ParseError
if the supplied argument is not a valid range.
# File lib/soroban/helpers.rb, line 55 def self.getRange(data) raise Soroban::ParseError, "invalid #getRange for '#{data}'" if !range?(data) /^([a-zA-Z]+)([\d]+):([a-zA-Z]+)([\d]+)$/.match(data.to_s).to_a[1..-1] end
Return an array of values for the supplied arguments (which may be numbers, labels and ranges).
# File lib/soroban/helpers.rb, line 71 def self.getValues(context, *args) args.map { |arg| range?(arg) ? Soroban::ValueWalker.new(arg, context).to_a : arg }.to_a.flatten end
Return true if the supplied data is a label.
# File lib/soroban/helpers.rb, line 31 def self.label?(data) /^([a-zA-Z]+)([\d]+)$/.match(data.to_s) && true || false end
Return true if the supplied data is a number.
# File lib/soroban/helpers.rb, line 13 def self.number?(data) Float(data.to_s) && true rescue false end
Return true if the supplied data is a range.
# File lib/soroban/helpers.rb, line 37 def self.range?(data) /^([a-zA-Z]+)([\d]+):([a-zA-Z]+)([\d]+)$/.match(data.to_s) && true || false end
Return true if the supplied data is a string.
# File lib/soroban/helpers.rb, line 24 def self.string?(data) /^["](\"|[^"])*["]$/.match(data.to_s) && true || /^['][^']*[']$/.match(data.to_s) && true || false end
Return true if the supplied data is of no recognised format.
# File lib/soroban/helpers.rb, line 43 def self.unknown?(data) !formula?(data) && !number?(data) && !boolean?(data) && !string?(data) && !label?(data) && !range?(data) end