File: matrix.rb

package info (click to toggle)
ruby-roo 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,216 kB
  • sloc: ruby: 6,529; xml: 88; makefile: 6
file content (23 lines) | stat: -rw-r--r-- 674 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Roo
  module Formatters
    module Matrix
      # returns a matrix object from the whole sheet or a rectangular area of a sheet
      def to_matrix(from_row = nil, from_column = nil, to_row = nil, to_column = nil, sheet = default_sheet)
        require 'matrix'

        return ::Matrix.empty unless first_row

        from_row ||= first_row(sheet)
        to_row ||= last_row(sheet)
        from_column ||= first_column(sheet)
        to_column ||= last_column(sheet)

        ::Matrix.rows(from_row.upto(to_row).map do |row|
          from_column.upto(to_column).map do |col|
            cell(row, col, sheet)
          end
        end)
      end
    end
  end
end