Sha256: 6ea595859325c8fccb4c742edd184aa68b9d123a92af6b38dc0b16a150acf9fa

Contents?: true

Size: 616 Bytes

Versions: 4

Compression:

Stored size: 616 Bytes

Contents

module EDN
  class Reader
    include Enumerable

    def initialize(text)
      @parser = Parser.new
      @transform = Transform.new
      @original_text = text
      @text = text
    end

    def eof?
      @text.nil? || @text.empty?
    end

    def each
      reset!
      return enum_for(:select) unless block_given?

      until eof?
        yield read
      end
    end

    def reset!
      @text = @original_text
    end

    def read
      raise "EDN::Reader is out of string!" if eof?
      element, rest = @parser.parse_prefix(@text)
      @text = rest
      @transform.apply(element)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
edn-1.0.3 lib/edn/reader.rb
edn-1.0.2 lib/edn/reader.rb
edn-1.0.1 lib/edn/reader.rb
edn-1.0.0 lib/edn/reader.rb