lib/sycsvpro/spread_sheet.rb
def [](*range)
      r, c = range
      r ||= 0..(nrows-1)
      c ||= 0..(ncols-1)
 
      row_selection = rows.values_at(*r)
      col_selection = []

      if rows_are_arrays?(row_selection)
        row_selection.each do |row|
          values = row.values_at(*c)
          col_selection << (values.respond_to?(:to_ary) ? values : [values])
        end 
      else
        col_selection << row_selection[*c]
      end

      SpreadSheet.new(*col_selection, 
                      row_labels: row_labels.values_at(*r),
                      col_labels: col_labels.values_at(*c))
    end
def [](*range)
      r, c = range
      r ||= 0..(nrows-1)
      c ||= 0..(ncols-1)
 
      row_selection = rows.values_at(*r)
      col_selection = []

      if rows_are_arrays?(row_selection)
        row_selection.each do |row|
          values = row.values_at(*c)
          col_selection << (values.respond_to?(:to_ary) ? values : [values])
        end 
      else
        col_selection << row_selection[*c]
      end

      SpreadSheet.new(*col_selection, 
                      row_labels: row_labels.values_at(*r),
                      col_labels: col_labels.values_at(*c))
    end
def [] ( * range ) r , c = range r ||= 0 .. ( nrows - 1 ) c ||= 0 .. ( ncols - 1 ) row_selection = rows . values_at ( r ) col_selection = [ ] if rows_are_arrays? ( row_selection ) row_selection . each do | row | values = row . values_at ( c ) col_selection << ( values . respond_to? ( :to_ary ) ? values : [ values ] ) end else col_selection << row_selection [ c ] end SpreadSheet . new ( col_selection , row_labels : row_labels . values_at ( r ) , col_labels : col_labels . values_at ( c ) ) end
Returns a subset of the spread sheet and returns a new spread sheet with
 the result and the corresponding row and column labels
Returns a subset of the spread sheet and returns a new spread sheet with the result and the corresponding row and column labels