Class: RubyXL::ColumnRanges

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

Instance Method Summary collapse

Methods inherited from OOXMLObject

define_attribute, define_child_node, define_element_name, #dup, #index_in_collection, #initialize, obtain_class_variable, parse, set_countable, #write_xml

Constructor Details

This class inherits a constructor from RubyXL::OOXMLObject

Instance Method Details

#before_write_xmlObject



68
69
70
# File 'lib/rubyXL/objects/column_range.rb', line 68

def before_write_xml
  !(column_ranges.nil? || column_ranges.empty?)
end

#find(col_index) ⇒ Object



60
61
62
# File 'lib/rubyXL/objects/column_range.rb', line 60

def find(col_index)
  column_ranges && column_ranges.find { |range| range.include?(col_index) }
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.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rubyXL/objects/column_range.rb', line 43

def get_range(col_index)
  col_num = col_index + 1

  old_range = self.find(col_index)

  if old_range.nil? then
    new_range = RubyXL::ColumnRange.new(:min => col_num, :max => col_num)
    self.column_ranges << new_range
    return new_range
  elsif old_range.min == col_num && 
          old_range.max == col_num then # Single column range, OK to change in place
    return old_range
  else
    raise "Range splitting not implemented yet"
  end
end

#insert_column(col_index) ⇒ Object



64
65
66
# File 'lib/rubyXL/objects/column_range.rb', line 64

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