Sha256: 36be068d683232b90aa5de209e13b5fa248a2a7ab333caa6ce5247fdb490ab03

Contents?: true

Size: 1.88 KB

Versions: 32

Compression:

Stored size: 1.88 KB

Contents

# encoding: UTF-8
require 'test_helper'

# This tests the README page example
class ReadmeTest < ActiveSupport::TestCase
  test 'readme example' do
    require 'ndr_import/non_tabular/table'
    require 'ndr_import/file/registry'

    unzip_path = SafePath.new('test_space_rw')
    source_file = SafePath.new('permanent_test_files').join('flat_file.pdf')
    options = { 'unzip_path' => unzip_path }

    table = NdrImport::NonTabular::Table.new(
      'start_in_a_record' => false,
      'end_in_a_record' => false,
      'klass' => 'SomeTestKlass',
      'start_line_pattern' => /\A------\z/,
      'remove_lines' => { 'footer' => [/\A== Page \d+ of \d+ ==\z/i] },
      'columns' => [
        {
          'column' => 'one',
          'non_tabular_cell' => { 'lines' => Range.new(0, -1, true), 'capture' => /^(.*)$/i }
        }
      ]
    )

    # Use the Registry to enumerate over the files and their tables
    files = NdrImport::File::Registry.files(source_file, options)
    files.each do |filename|
      tables = NdrImport::File::Registry.tables(filename, nil, options)
      tables.each do |_tablename, table_content|
        # Use the NonTabular::Table to tabulate the "table" contents
        table.transform(table_content).each do |_klass, _fields, _index|
          # Your code goes here
        end

        # Now we test the example
        results = []
        table.transform(table_content).each do |_klass, fields, _index|
          results << fields[:rawtext]['one']
        end
        assert table.is_a?(NdrImport::NonTabular::Table)
        assert_equal 4, results.count
        assert results.first.start_with?('1')
        assert results.last.start_with?('4')
        assert results.any? { |result| result =~ /This is captured/ }
        refute results.any? { |result| result =~ /This is never captured/ }
        refute results.any? { |result| result =~ /== Page/ }
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
ndr_import-8.5.0 test/readme_test.rb
ndr_import-8.4.0 test/readme_test.rb
ndr_import-8.3.0 test/readme_test.rb
ndr_import-8.2.0 test/readme_test.rb
ndr_import-8.1.0 test/readme_test.rb
ndr_import-8.0.0 test/readme_test.rb
ndr_import-7.0.0 test/readme_test.rb
ndr_import-6.4.1 test/readme_test.rb
ndr_import-6.4.0 test/readme_test.rb
ndr_import-6.3.0 test/readme_test.rb
ndr_import-6.2.0 test/readme_test.rb
ndr_import-6.1.1 test/readme_test.rb
ndr_import-6.1.0 test/readme_test.rb
ndr_import-6.0.0 test/readme_test.rb
ndr_import-5.1.0 test/readme_test.rb
ndr_import-5.0.0 test/readme_test.rb
ndr_import-4.1.4 test/readme_test.rb
ndr_import-4.1.3 test/readme_test.rb
ndr_import-4.1.2 test/readme_test.rb
ndr_import-4.1.1 test/readme_test.rb