Sha256: eba0e8d13fa53841794edff8eeb030d65389969b8b296fe4075c42ceaa8dd982

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

require 'helper'

describe RemoteTable do
  describe ":parser option" do
    it "takes a parser object that responds to #call(row) and returns an array of rows" do
      class GradeRangeParser
        def call(row)
          row['range'].split('-').map do |subrange|
            virtual_row = row.dup
            virtual_row.delete 'range'
            virtual_row['grade'] = subrange
            virtual_row
          end
        end
      end
      t = RemoteTable.new "file://#{File.expand_path('../data/ranges.csv', __FILE__)}", parser: GradeRangeParser.new
      t[0].must_equal 'description' => 'great', 'grade' => 'A'
      t[1].must_equal 'description' => 'great', 'grade' => 'B'
      t[2].must_equal 'description' => 'ok', 'grade' => 'C'
      t[3].must_equal 'description' => 'bad', 'grade' => 'D'
      t[4].must_equal 'description' => 'bad', 'grade' => 'F'
    end

    it "takes a proc and returns an array of rows" do
      grade_range_parser_proc = lambda do |row|
        row['range'].split('-').map do |subrange|
          virtual_row = row.dup
          virtual_row.delete 'range'
          virtual_row['grade'] = subrange
          virtual_row
        end
      end
      t = RemoteTable.new "file://#{File.expand_path('../data/ranges.csv', __FILE__)}", parser: grade_range_parser_proc
      t[0].must_equal 'description' => 'great', 'grade' => 'A'
      t[1].must_equal 'description' => 'great', 'grade' => 'B'
      t[2].must_equal 'description' => 'ok', 'grade' => 'C'
      t[3].must_equal 'description' => 'bad', 'grade' => 'D'
      t[4].must_equal 'description' => 'bad', 'grade' => 'F'
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
remote_table-3.3.3 test/test_parser.rb
remote_table-3.3.2 test/test_parser.rb
remote_table-3.3.0 test/test_parser.rb
remote_table-3.2.1 test/test_parser.rb
remote_table-3.2.0 test/test_parser.rb
remote_table-3.1.0 test/test_parser.rb
remote_table-3.0.0 test/test_parser.rb
remote_table-3.0.0.rc2 test/test_parser.rb
remote_table-3.0.0.rc1 test/test_parser.rb