Sha256: e847c08cdaa19b4709040cc47dee5928270111e24094fe5d34fcfc452428373b

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

require_relative 'worksheet'

module Workbook

  def self.rubyxl_to_hash(rubyxl_workbook)
    hash_workbook = {}
    rubyxl_workbook.each do |rubyxl_worksheet|
      hash_workbook[rubyxl_worksheet.sheet_name] = Worksheet.rubyxl_to_hash(rubyxl_worksheet)
    end
    hash_workbook
  end

  def self.hash_workbook_to_rubyxl_workbook(hash_workbook)
    validate_hash_workbook(hash_workbook)
    rubyxl_workbook = RubyXL::Workbook.new
    first_worksheet = true
    hash_workbook.each do |hash_key, hash_value|
      if first_worksheet
        rubyxl_workbook.worksheets[0].sheet_name = hash_key
        first_worksheet = false
      else
        rubyxl_workbook.add_worksheet(hash_key)
      end
      Worksheet.set_hash_worksheet_defaults(hash_value)
      Worksheet.hash_worksheet_to_rubyxl_worksheet(hash_value, rubyxl_workbook[hash_key])
    end
    rubyxl_workbook
  end

  def self.hash_workbook_to_hash_tables(hash_workbook)
    hash_workbook.keys.each_with_object({}) do |key, hash_tables|
      hash_tables[key] = Worksheet.hash_worksheet_to_hash_table(hash_workbook[key])
    end
  end

  def self.validate_hash_workbook(hash_workbook)
    raise('workbook must be a Hash') unless hash_workbook.is_a?(Hash)
    hash_workbook.each do |hash_worksheet_name, hash_worksheet|
      Worksheet.validate_hash_worksheet(hash_worksheet_name, hash_worksheet)
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rxl-0.2.0 lib/workbook.rb
rxl-0.1.4 lib/workbook.rb
rxl-0.1.3 lib/workbook.rb
rxl-0.1.2 lib/workbook.rb
rxl-0.1.1 lib/workbook.rb
rxl-0.1.0 lib/workbook.rb