Sha256: 7cd52f39a8834a4d94531d981f999fd92a01079cf49f469df3ef5c0268840361

Contents?: true

Size: 902 Bytes

Versions: 3

Compression:

Stored size: 902 Bytes

Contents

module Alf
  class Reader
    #
    # Specialization of the Reader contract for .rash files.
    #
    # A .rash file/stream contains one ruby hash literal on each line. This reader simply
    # decodes each of them in turn with Kernel.eval, providing a state-less reader (that
    # is, tuples are not all loaded in memory at once).
    #
    class Rash < Reader

      def self.mime_type
        nil
      end

      # (see Reader#line2tuple)
      def line2tuple(line)
        return nil if line.strip.empty?
        begin
          h = Kernel.eval(line)
          raise "Tuple expected, got `#{h.inspect}`" unless TupleLike===h
        rescue Exception => ex
          $stderr << "Skipping `#{line.strip}`: #{ex.message}\n"
          nil
        else
          return h
        end
      end

      Reader.register(:rash, [".rash"], self)
    end # class Rash
  end # class Reader
end # module Alf

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alf-core-0.15.0 lib/alf/reader/rash.rb
alf-core-0.14.0 lib/alf-io/alf/reader/rash.rb
alf-core-0.13.1 lib/alf-io/alf/reader/rash.rb