Class: RubyXL::ColumnRanges

Inherits:
OOXMLContainerObject show all
Defined in:
lib/rubyXL/objects/column_range.rb

Instance Attribute Summary

Attributes included from OOXMLObjectInstanceMethods

#local_namespaces

Instance Method Summary collapse

Methods inherited from OOXMLContainerObject

define_count_attribute, #initialize, #inspect

Methods included from OOXMLObjectInstanceMethods

#==, included, #index_in_collection, #initialize, #write_xml

Constructor Details

This class inherits a constructor from RubyXL::OOXMLContainerObject

Instance Method Details

#before_write_xmlObject

[View source]

88
89
90
91
# File 'lib/rubyXL/objects/column_range.rb', line 88

def before_write_xml
  self.sort_by!(&:min)
  !self.empty?
end

#get_range(col_index) ⇒ Object

Locate an existing column range, make a new one if not found, or split existing column range into multiples.

[View source]

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rubyXL/objects/column_range.rb', line 48

def get_range(col_index)
  col_num = col_index + 1

  old_range = self.locate_range(col_index)

  if old_range.nil? then
    new_range = RubyXL::ColumnRange.new(width: RubyXL::ColumnRange.chars2raw(RubyXL::ColumnRange::DEFAULT_WIDTH))
  else
    if old_range.min == col_num && old_range.max == col_num then
      return old_range # Single column range, OK to change in place
    elsif old_range.min == col_num then
      new_range = old_range.dup
      old_range.min += 1
    elsif old_range.max == col_num then
      new_range = old_range.dup
      old_range.max -= 1
    else
      prior_range = old_range.dup
      prior_range.max = col_index # col_num - 1
      self << prior_range

      old_range.min = col_num + 1

      new_range = RubyXL::ColumnRange.new
    end
  end

  new_range.min = new_range.max = col_num
  self << new_range
  return new_range
end

#insert_column(col_index) ⇒ Object

[View source]

84
85
86
# File 'lib/rubyXL/objects/column_range.rb', line 84

def insert_column(col_index)
  self.each { |range| range.insert_column(col_index) }
end

#locate_range(col_index) ⇒ Object

[View source]

80
81
82
# File 'lib/rubyXL/objects/column_range.rb', line 80

def locate_range(col_index)
  self.find { |range| range.include?(col_index) }
end