Class: Campa::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/campa/reader.rb

Overview

Reads strings or files into Campa expressions. rubocop: disable Metrics/ClassLength

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Reader

Given a String, a file pointer or any #getc, #eof? it allows fetch every valid Campa form from it.

If the String is a valid file path it will be converted into a file pointer. Anything else will be converted into a StringIO

Parameters:

  • input (String, (#getc, #eof?))


17
18
19
20
# File 'lib/campa/reader.rb', line 17

def initialize(input)
  @input = to_io_like(input)
  next_char
end

Instance Method Details

#nextObject

Return the next Campa form available in the underlying io like object.

Returns:

  • (Object)

    next available Campa form



26
27
28
29
30
31
32
33
# File 'lib/campa/reader.rb', line 26

def next
  eat_separators
  return read if !@input.eof?
  return if @current_char.nil?

  # Exhaust the reader if @input.eof? and !@current_char.nil?
  read.tap { @current_char = nil }
end