Sha256: 22eb658fb84eeebb52e7eb69e9e5e411d897220700bf1b38c5e6f591eef763f4

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 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.hash_worksheet_to_rubyxl_worksheet(hash_value, rubyxl_workbook[hash_key])
    end
    rubyxl_workbook
  end

  def self.hashes_to_hash_workbook(hash_tables, order, write_headers: true)
    hash_workbook = {}
    hash_tables.each { |k, v| hash_workbook[k] = Worksheet.hashes_to_hash_worksheet(v, order, write_headers: write_headers) }
    hash_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

1 entries across 1 versions & 1 rubygems

Version Path
rxl-0.3.0 lib/workbook.rb