lib/soroban/sheet.rb in soroban-0.3.1 vs lib/soroban/sheet.rb in soroban-0.4.0

- old
+ new

@@ -9,11 +9,12 @@ # A container for cells. class Sheet attr_reader :bindings # Creates a new sheet. - def initialize + def initialize(logger=nil) + @logger = logger @cells = {} @bindings = {} end # Used for calling dynamically defined functions, and for creating new @@ -28,12 +29,14 @@ end # Set the contents of one or more cells or ranges. def set(options_hash) options_hash.each do |label_or_range, contents| + _debug("setting '#{label_or_range}' to '#{contents}'") unless range = Soroban::getRange(label_or_range) - return _add(label_or_range, contents) + _add(label_or_range, contents) + next end fc, fr, tc, tr = range if fc == tc || fr == tr raise ArgumentError, "Expecting an array when setting #{label_or_range}" unless contents.kind_of? Array cc, cr = fc, fr @@ -50,20 +53,22 @@ end # Retrieve the contents of a cell. def get(label_or_name) label = @bindings[label_or_name.to_sym] || label_or_name + _debug("retrieving '#{label_or_name}' from '#{label}'}") if Soroban::range?(label) walk(label) else _get(label_or_name, eval("@#{label}", binding)) end end # Bind one or more named variables to a cell. def bind(options_hash) options_hash.each do |name, label_or_range| + _debug("binding '#{name}' to '#{label_or_range}'}") if Soroban::range?(label_or_range) LabelWalker.new(label_or_range).each do |label| next if @cells.keys.include?(label.to_sym) raise Soroban::UndefinedError, "Cannot bind '#{name}' to range '#{label_or_range}'; cell #{label} is not defined" end @@ -93,9 +98,14 @@ def missing @cells.values.flatten.uniq - @cells.keys end private + + def _debug(message) + return if @logger.nil? + @logger.debug "SOROBAN: #{message}" + end def _add(label, contents) internal = "@#{label}" _expose(internal, label) cell = Cell.new(binding)