Class: Xlsxrb::Elements::Column

Inherits:
Data
  • Object
show all
Defined in:
lib/xlsxrb/elements/column.rb

Overview

Represents column formatting in a worksheet. index is 0-based.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index:, width: nil, hidden: false, custom_width: false, outline_level: nil, unmapped_data: {}, errors: nil) ⇒ Column

Returns a new instance of Column.



8
9
10
11
12
13
14
# File 'lib/xlsxrb/elements/column.rb', line 8

def initialize(index:, width: nil, hidden: false, custom_width: false, outline_level: nil,
               unmapped_data: {}, errors: nil)
  computed_errors = errors || self.class.validate(index)
  super(index: index, width: width, hidden: hidden, custom_width: custom_width,
        outline_level: outline_level, unmapped_data: unmapped_data,
        errors: computed_errors.freeze)
end

Instance Attribute Details

#custom_widthObject (readonly)

Returns the value of attribute custom_width

Returns:

  • (Object)

    the current value of custom_width



7
8
9
# File 'lib/xlsxrb/elements/column.rb', line 7

def custom_width
  @custom_width
end

#errorsObject (readonly)

Returns the value of attribute errors

Returns:

  • (Object)

    the current value of errors



7
8
9
# File 'lib/xlsxrb/elements/column.rb', line 7

def errors
  @errors
end

#hiddenObject (readonly)

Returns the value of attribute hidden

Returns:

  • (Object)

    the current value of hidden



7
8
9
# File 'lib/xlsxrb/elements/column.rb', line 7

def hidden
  @hidden
end

#indexObject (readonly)

Returns the value of attribute index

Returns:

  • (Object)

    the current value of index



7
8
9
# File 'lib/xlsxrb/elements/column.rb', line 7

def index
  @index
end

#outline_levelObject (readonly)

Returns the value of attribute outline_level

Returns:

  • (Object)

    the current value of outline_level



7
8
9
# File 'lib/xlsxrb/elements/column.rb', line 7

def outline_level
  @outline_level
end

#unmapped_dataObject (readonly)

Returns the value of attribute unmapped_data

Returns:

  • (Object)

    the current value of unmapped_data



7
8
9
# File 'lib/xlsxrb/elements/column.rb', line 7

def unmapped_data
  @unmapped_data
end

#widthObject (readonly)

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



7
8
9
# File 'lib/xlsxrb/elements/column.rb', line 7

def width
  @width
end

Class Method Details

.validate(index) ⇒ Object



20
21
22
23
24
25
# File 'lib/xlsxrb/elements/column.rb', line 20

def self.validate(index)
  errs = []
  errs << "index must be a non-negative Integer (got #{index.inspect})" if !index.is_a?(Integer) || index.negative?
  errs << "index must be < 16384 (got #{index}, max column is XFD=16383)" if index.is_a?(Integer) && index >= 16_384
  errs
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/xlsxrb/elements/column.rb', line 16

def valid?
  errors.empty?
end