class Soroban::Import::RubyXLImporter

Public Class Methods

new(path, index, bindings) click to toggle source
# File lib/soroban/import/ruby_xl_importer.rb, line 20
def initialize(path, index, bindings)
  @_path, @_index, @_bindings = path, index, bindings
  @_sheet = nil
  @_model = nil
end

Public Instance Methods

import() click to toggle source
# File lib/soroban/import/ruby_xl_importer.rb, line 26
def import
  workbook = RubyXL::Parser.parse(@_path)
  @_sheet = workbook.worksheets[@_index]
  @_model = Soroban::Sheet.new
  @_bindings.values.each do |label_or_range|
    if Soroban::Helpers::range?(label_or_range)
      Soroban::LabelWalker.new(label_or_range).each do |label|
        _addCell(label)
      end
    else
      _addCell(label_or_range)
    end
  end
  while label = @_model.missing.first
    _addCell(label)
  end
  @_model.bind(@_bindings)
  return @_model
end

Private Instance Methods

_addCell(label) click to toggle source
# File lib/soroban/import/ruby_xl_importer.rb, line 48
def _addCell(label)
  row, col = Soroban::Helpers::getPos(label)
  cell = @_sheet[row][col]
  data = cell.formula rescue nil
  data = "=#{data}" unless data.nil?
  data ||= cell.value.to_s rescue nil
  @_model.set(label.to_sym => data)
end