Sha256: 1df4bdc9aa623fc37a4fcb851991a32c9c3c27e4d28830b7e991b21c8f6e5168

Contents?: true

Size: 738 Bytes

Versions: 3

Compression:

Stored size: 738 Bytes

Contents

module RecordSearch

  # Used when indexing. You can create subclass to give the indexer the data
  # it needs.
  class DataSource
    # Returns the next record. The method in this class is abstract (or it
    # tries to) It raises an exception telling you to implement it.
    def next
      raise 'you must implement this method!'
    end
  end

  # A DataSource which reads from a text file.
  class FileDataSource < DataSource
    # Creates a new FileDataSource using the value of fname as the file name.
    def initialize(fname)
      @file = File.open(fname, 'r')
    end

    # Closes the file.
    def close
      @file.close
      @file = nil
    end

    # Reads the next line.
    def next
      @file.gets
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
recordsearch-1.1.1 lib/recordsearch/data_source.rb
recordsearch-1.1.0 lib/recordsearch/data_source.rb
recordsearch-1.0.0 lib/recordsearch/data_source.rb