<commit_before>module Ods
  class Sheet
    attr_reader :content

    def initialize(content)
      @content = content
    end

    def name
      content.attribute('name').to_s
    end

    # access by (0,0) = top left
    def [](row_index, col_index)
      row = data[row_index]
      row && row[col_index]
    end

    def rows
      return @rows if @rows
      @rows = []
      content.xpath('descendant::table:table-row').each do |node|
        a_row = Row.new(node, self)
        if a_row.data.length > 0
          repeat = node['table:number-rows-repeated'] || 1
          repeat.to_i.times do
            @rows << a_row
          end
        end
      end
      @rows
    end

    def data
      @data ||= rows.map(&:data).reject { |row| row.length == 0 }
    end

    def csv
      CSV do |csv|
        data.each { |row| csv << row }
      end<commit_msg>ignore trailing empty rows<commit_after>module Ods
  class Sheet
    attr_reader :content

    def initialize(content)
      @content = content
    end

    def name
      content.attribute('name').to_s
    end

    # access by (0,0) = top left
    def [](row_index, col_index)
      row = data[row_index]
      row && row[col_index]
    end

    def rows
      return @rows if @rows
      @rows = []
      src_rows = content.xpath('descendant::table:table-row')

      # ignore trailing empty rows
      while (last_row = src_rows.last) && (Row.new(last_row, self).data.length == 0)
        src_rows.pop
      end

      src_rows.each do |node|
        a_row = Row.new(node, self)
        repeat = node['table:number-rows-repeated'] || 1
        repeat.to_i.times do
          @rows << a_row
        end
      end
      @rows
    end

    def data
      @data ||= rows.map(&:data)
    end

    def csv
      CSV do |csv|
        data.each { |row| csv << row }
      end
{'fraction_non_alphanumeric': 0.11232279171210469, 'fraction_numerical': 0.004907306434023991, 'mean_word_length': 1.8187403993855606, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6463391', 'n_tokens_mistral': 622, 'n_tokens_neox': 596, 'n_words': 157}