Sha256: 299826ccd0299000fa58955d6e268d826a6fbf9abd654b44ac4a5c974dd32653

Contents?: true

Size: 908 Bytes

Versions: 29

Compression:

Stored size: 908 Bytes

Contents

class RemoteTable
  module RooSpreadsheet
    def each_row(&block)
      headers = Hash.new
      oo = roo_klass.new(path, nil, :ignore)
      oo.default_sheet = sheet.is_a?(Numeric) ? oo.sheets[sheet] : sheet
      for col in (1..oo.last_column)
        headers[col] = oo.cell(header_row, col)
        headers[col] = oo.cell(header_row - 1, col) if headers[col].blank? # look up
      end
      first_data_row.upto(oo.last_row) do |raw_row|
        ordered_hash = ActiveSupport::OrderedHash.new
        for col in (1..oo.last_column)
          next if headers[col].blank?
          ordered_hash[headers[col]] = oo.cell(raw_row, col).to_s.gsub(/<[^>]+>/, '').strip
        end
        yield ordered_hash if keep_blank_rows or ordered_hash.any? { |k, v| v.present? }
      end
    end

    private

    def header_row
      1 + skip.to_i
    end

    def first_data_row
      1 + header_row
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
remote_table-0.2.29 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.28 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.27 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.26 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.24 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.23 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.22 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.21 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.20 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.19 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.18 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.17 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.16 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.15 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.14 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.13 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.12 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.11 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.10 lib/remote_table/file/roo_spreadsheet.rb
remote_table-0.2.9 lib/remote_table/file/roo_spreadsheet.rb