Class: Spreadsheet::Column

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Datatypes
Defined in:
lib/spreadsheet/column.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Datatypes

append_features

Methods included from Compatibility

#ivar_name, #method_name

Constructor Details

#initialize(idx, format, opts = {}) ⇒ Column

Returns a new instance of Column.



41
42
43
44
45
46
47
48
49
# File 'lib/spreadsheet/column.rb', line 41

def initialize idx, format, opts={}
  @worksheet = nil
  @idx = idx
  opts[:width] ||= 10
  opts.each do |key, value|
    self.send "#{key}=", value
  end
  self.default_format = format
end

Instance Attribute Details

#default_formatObject

Returns the value of attribute default_format.



37
38
39
# File 'lib/spreadsheet/column.rb', line 37

def default_format
  @default_format
end

#idxObject (readonly)

Returns the value of attribute idx.



37
38
39
# File 'lib/spreadsheet/column.rb', line 37

def idx
  @idx
end

#widthObject

Returns the value of attribute width.



36
37
38
# File 'lib/spreadsheet/column.rb', line 36

def width
  @width
end

#worksheetObject

Returns the value of attribute worksheet.



36
37
38
# File 'lib/spreadsheet/column.rb', line 36

def worksheet
  @worksheet
end

Class Method Details

.updater(*keys) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/spreadsheet/column.rb', line 21

def updater *keys
  keys.each do |key|
    unless instance_methods.include? "unupdated_#{key}="
      alias_method :"unupdated_#{key}=", :"#{key}="
      define_method "#{key}=" do |value|
        send "unupdated_#{key}=", value
        @worksheet.column_updated @idx, self if @worksheet
        value
      end
    end
  end
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



65
66
67
68
69
# File 'lib/spreadsheet/column.rb', line 65

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

#eachObject

Iterate over all cells in this column.



60
61
62
63
64
# File 'lib/spreadsheet/column.rb', line 60

def each
  @worksheet.each do |row|
    yield row[idx]
  end
end