Sha256: 89a2a76b2c5d177ea5efe2274d21580c35cbab4e79c81b9b45af287ed3ed80d6

Contents?: true

Size: 1.11 KB

Versions: 19

Compression:

Stored size: 1.11 KB

Contents

module Index
  
  module File
    
    # Index data dumped in the text format.
    #
    class Text < Basic
      
      # Uses the extension "txt".
      #
      def extension
        :txt
      end
      # Text files are used exclusively for
      # prepared data files.
      #
      def load
        raise "Can't load from text file. Use JSON or Marshal."
      end
      # Text files are used exclusively for
      # prepared data files. 
      #
      def dump hash
        raise "Can't dump to text file. Use JSON or Marshal."
      end
      
      # Retrieves prepared index data in the form
      # * id,data\n
      # * id,data\n
      # * id,data\n
      #
      # Yields an id and a symbol token.
      #
      def retrieve
        id, token =
        ::File.open(cache_path, 'r:binary') do |file|
          file.each_line do |line|
            id, token = line.split ?,, 2
            yield id.to_i, (token.chomp! || token).to_sym
          end
        end
      end
      
      #
      #
      def open_for_indexing &block
        ::File.open cache_path, 'w:binary', &block
      end
      
      
    end
    
  end
  
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
picky-1.3.0 lib/picky/index/file/text.rb
picky-1.2.4 lib/picky/index/file/text.rb
picky-1.2.3 lib/picky/index/file/text.rb
picky-1.2.2 lib/picky/index/file/text.rb
picky-1.2.1 lib/picky/index/file/text.rb
picky-1.2.0 lib/picky/index/file/text.rb
picky-1.1.7 lib/picky/index/file/text.rb
picky-1.1.6 lib/picky/index/file/text.rb
picky-1.1.5 lib/picky/index/file/text.rb
picky-1.1.4 lib/picky/index/file/text.rb
picky-1.1.3 lib/picky/index/file/text.rb
picky-1.1.2 lib/picky/index/file/text.rb
picky-1.1.1 lib/picky/index/file/text.rb
picky-1.1.0 lib/picky/index/file/text.rb
picky-1.0.0 lib/picky/index/file/text.rb
picky-0.12.3 lib/picky/index/file/text.rb
picky-0.12.2 lib/picky/index/file/text.rb
picky-0.12.1 lib/picky/index/file/text.rb
picky-0.12.0 lib/picky/index/file/text.rb