Module: RubyXL::Addressing
- Defined in:
- lib/rubyXL/addressing.rb,
lib/rubyXL/addressing/version.rb
Constant Summary collapse
- ROW_REF_FORMAT =
/\A[1-9]\d*\z/- COLUMN_REF_FORMAT =
/\A[A-Z]+\z/- VERSION =
'0.2.0'
Class Method Summary collapse
- .column_ind2ref(ind) ⇒ String
- .column_ref2ind(ref) ⇒ Integer
- .row_ind2ref(ind) ⇒ String
- .row_ref2ind(ref) ⇒ Integer
Instance Method Summary collapse
Class Method Details
.column_ind2ref(ind) ⇒ String
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubyXL/addressing.rb', line 24 def column_ind2ref(ind) validate_index('column', ind) ref = ''.dup loop do ref.prepend((ind % 26 + 65).chr) ind = ind / 26 - 1 break if ind < 0 end ref.freeze end |
.column_ref2ind(ref) ⇒ Integer
47 48 49 50 51 52 |
# File 'lib/rubyXL/addressing.rb', line 47 def column_ref2ind(ref) = "invalid column #{ref.inspect}" raise ArgumentError, unless COLUMN_REF_FORMAT =~ ref ref.to_s.each_byte.reduce(0) { |a, e| a * 26 + (e - 64) } - 1 end |
.row_ind2ref(ind) ⇒ String
16 17 18 19 20 |
# File 'lib/rubyXL/addressing.rb', line 16 def row_ind2ref(ind) validate_index('row', ind) (ind + 1).to_s.freeze end |
.row_ref2ind(ref) ⇒ Integer
38 39 40 41 42 43 |
# File 'lib/rubyXL/addressing.rb', line 38 def row_ref2ind(ref) = "invalid row #{ref.inspect}" raise ArgumentError, unless ROW_REF_FORMAT =~ ref ref.to_s.to_i - 1 end |
Instance Method Details
#addr(ref_or_row, column = nil) ⇒ RubyXL::Address
79 80 81 82 83 84 85 |
# File 'lib/rubyXL/addressing.rb', line 79 def addr(ref_or_row, column = nil) if column.nil? Address.new(self, ref: ref_or_row) else Address.new(self, row: ref_or_row, column: column) end end |