Sha256: 9002ef8e749b98e074f44d9e27c08be01321f3a4c9cbd6446af22a705864c1cb
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 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, write_headers: true) hash_workbook = {} hash_tables.each do |k, v| hash_workbook[k] = Worksheet.hashes_to_hash_worksheet(v[:rows], v[:columns], v[:formats] || {}, write_headers: write_headers) end 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rxl-0.6.1 | lib/workbook.rb |
rxl-0.6.0 | lib/workbook.rb |