Sha256: cfccbc224f2ee45e51183714e8f8092fc3d76f4c043d56e625df43b101b56403

Contents?: true

Size: 977 Bytes

Versions: 2

Compression:

Stored size: 977 Bytes

Contents

module XLSX
  class Workbook
    attr_accessor :sheets # an array of all the sheets in this workbook.
    attr_accessor :strings # :nodoc:
    
    # create a new work book
    def initialize
      @sheets = Array.new
      @strings = Array.new
    end
    
    # Add a new sheet with name.
    def add_sheet(name)
      sheet = Sheet.new
      @sheets.push(sheet)
      sheet.id = @sheets.size
      sheet.name = name
      sheet.hash = Digest::SHA1.hexdigest("#{name}--#{sheet.id}")
      sheet.workbook = self
      yield(sheet) if block_given?
      sheet
    end
    
    # Get the data.
    def build
      ::XLSX::Formatter.build(self)
    end
    
    # Write the data to an .xlsx file
    def dump(path=nil)
      ::XLSX::Formatter.dump(self, path)
    end
    
    def register_string(string) # :nodoc:
      index = @strings.index(string)
      if index.nil?
        index = @strings.size
        @strings.push string
      end
      index
    end
    
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simonmenke-xlsx-0.0.1 lib/xlsx/workbook.rb
simonmenke-xlsx-0.0.2 lib/xlsx/workbook.rb