Sha256: 6ddd2d5887c0505a0d2a25be0e413b3468309c7df59ae6708167dd6f55263a81

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 KB

Contents

require 'spreadsheet/datatypes'

module Spreadsheet
  ##
  # The Column class. Encapsulates column-formatting and width, and provides a
  # means to iterate over all cells in a column.
  #
  # Useful Attributes:
  # #width::          The width in characters (in respect to the '0' character
  #                   of the Worksheet's default Font). Float values are
  #                   permitted, for Excel the available Precision is at 1/256
  #                   characters.
  # #default_format:: The default Format for cells in this column (applied if
  #                   there is no explicit Cell Format and no default Row format
  #                   for the Cell).
  # #hidden::         The Column is hidden.
  # #collapsed::      The Column is collapsed.
  # #outline_level::  Outline level of the column.
  class Column
    include Datatypes
    include Enumerable
    attr_accessor :width, :worksheet
    attr_reader :default_format, :idx
    boolean :hidden, :collapsed
    enum :outline_level, 0, Integer
    def initialize idx, format, opts={}
      @idx = idx
      opts[:width] ||= 10
      opts.each do |key, value|
        self.send "#{key}=", value
      end
      self.default_format = format
    end
    ##
    # Set the default Format for Cells in this Column.
    def default_format= format
      @worksheet.add_format format if @worksheet
      @default_format = format
    end
    ##
    # Iterate over all cells in this column.
    def each
      @worksheet.each do |row|
        yield row[idx]
      end
    end
    def == other # :nodoc:
      other.is_a?(Column) && default_format == other.default_format \
        && width == other.width && hidden == other.hidden \
        && collapsed == other.collapsed && outline_level == other.outline_level
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spreadsheet-0.6.1.3 lib/spreadsheet/column.rb
spreadsheet-0.6.1.1 lib/spreadsheet/column.rb
spreadsheet-0.6.1.2 lib/spreadsheet/column.rb
spreadsheet-0.6.1.4 lib/spreadsheet/column.rb
spreadsheet-0.6.1.5 lib/spreadsheet/column.rb