Class: RubyXL::ColumnRange
- Inherits:
-
Object
- Object
- RubyXL::ColumnRange
- Defined in:
- lib/rubyXL/objects/column_range.rb
Instance Attribute Summary collapse
-
#custom_width ⇒ Object
minandmaxare column 0-based indices, as opposed to Excel’s 1-based column numbers. -
#max ⇒ Object
minandmaxare column 0-based indices, as opposed to Excel’s 1-based column numbers. -
#min ⇒ Object
minandmaxare column 0-based indices, as opposed to Excel’s 1-based column numbers. -
#style_index ⇒ Object
minandmaxare column 0-based indices, as opposed to Excel’s 1-based column numbers. -
#width ⇒ Object
minandmaxare column 0-based indices, as opposed to Excel’s 1-based column numbers.
Class Method Summary collapse
- .find(col_index, ranges) ⇒ Object
- .ind2ref(ind) ⇒ Object
- .insert_column(col_index, ranges) ⇒ Object
- .parse(node) ⇒ Object
- .ref2ind(ref) ⇒ Object
-
.update(col_index, ranges, attrs) ⇒ Object
This method is used to change attributes on a column range, which may involve splitting existing column range into multiples.
Instance Method Summary collapse
- #delete_column(col) ⇒ Object
- #include?(col_index) ⇒ Boolean
-
#initialize(attrs = {}) ⇒ ColumnRange
constructor
A new instance of ColumnRange.
- #insert_column(col) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ ColumnRange
Returns a new instance of ColumnRange.
7 8 9 10 11 12 13 |
# File 'lib/rubyXL/objects/column_range.rb', line 7 def initialize(attrs = {}) @min = attrs['min'] @max = attrs['max'] @width = attrs['width'] @custom_width = attrs['customWidth'] @style_index = attrs['style'] end |
Instance Attribute Details
#custom_width ⇒ Object
min and max are column 0-based indices, as opposed to Excel’s 1-based column numbers
5 6 7 |
# File 'lib/rubyXL/objects/column_range.rb', line 5 def custom_width @custom_width end |
#max ⇒ Object
min and max are column 0-based indices, as opposed to Excel’s 1-based column numbers
5 6 7 |
# File 'lib/rubyXL/objects/column_range.rb', line 5 def max @max end |
#min ⇒ Object
min and max are column 0-based indices, as opposed to Excel’s 1-based column numbers
5 6 7 |
# File 'lib/rubyXL/objects/column_range.rb', line 5 def min @min end |
#style_index ⇒ Object
min and max are column 0-based indices, as opposed to Excel’s 1-based column numbers
5 6 7 |
# File 'lib/rubyXL/objects/column_range.rb', line 5 def style_index @style_index end |
#width ⇒ Object
min and max are column 0-based indices, as opposed to Excel’s 1-based column numbers
5 6 7 |
# File 'lib/rubyXL/objects/column_range.rb', line 5 def width @width end |
Class Method Details
.find(col_index, ranges) ⇒ Object
65 66 67 |
# File 'lib/rubyXL/objects/column_range.rb', line 65 def self.find(col_index, ranges) ranges.find { |range| range.include?(col_index) } end |
.ind2ref(ind) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rubyXL/objects/column_range.rb', line 75 def self.ind2ref(ind) str = '' loop do x = ind % 26 str = ('A'.ord + x).chr + str ind = (ind / 26).floor - 1 return str if ind < 0 end end |
.insert_column(col_index, ranges) ⇒ Object
35 36 37 |
# File 'lib/rubyXL/objects/column_range.rb', line 35 def self.insert_column(col_index, ranges) ranges.each { |range| range.insert_column(col_index) } end |
.parse(node) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/rubyXL/objects/column_range.rb', line 15 def self.parse(node) range = self.new range.min = RubyXL::Parser.attr_int(node, 'min') - 1 range.max = RubyXL::Parser.attr_int(node, 'max') - 1 range.width = RubyXL::Parser.attr_float(node, 'width') range.custom_width = RubyXL::Parser.attr_int(node, 'customWidth') range.style_index = RubyXL::Parser.attr_int(node, 'style') range end |
.ref2ind(ref) ⇒ Object
69 70 71 72 73 |
# File 'lib/rubyXL/objects/column_range.rb', line 69 def self.ref2ind(ref) col = 0 ref.each_byte { |chr| col = col * 26 + (chr - 64) } col - 1 end |
.update(col_index, ranges, attrs) ⇒ Object
This method is used to change attributes on a column range, which may involve splitting existing column range into multiples.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rubyXL/objects/column_range.rb', line 45 def self.update(col_index, ranges, attrs) old_range = RubyXL::ColumnRange.find(col_index, ranges) if old_range.nil? then new_range = RubyXL::ColumnRange.new(attrs.merge({ 'min' => col_index, 'max' => col_index })) ranges << new_range return new_range elsif old_range.min == col_index && old_range.max == col_index then # Single column range, OK to change in place old_range.width = attrs['width'] if attrs['width'] old_range.custom_width = attrs['customWidth'] if attrs['customWidth'] old_range.style_index = attrs['style'] if attrs['style'] return old_range else raise "Range splitting not implemented yet" end end |
Instance Method Details
#delete_column(col) ⇒ Object
25 26 27 28 |
# File 'lib/rubyXL/objects/column_range.rb', line 25 def delete_column(col) self.min -=1 if min >= col self.max -=1 if max >= col end |
#include?(col_index) ⇒ Boolean
39 40 41 |
# File 'lib/rubyXL/objects/column_range.rb', line 39 def include?(col_index) (min..max).include?(col_index) end |
#insert_column(col) ⇒ Object
30 31 32 33 |
# File 'lib/rubyXL/objects/column_range.rb', line 30 def insert_column(col) self.min +=1 if min >= col self.max +=1 if max >= col - 1 end |