Class: Campa::Reader
- Inherits:
-
Object
- Object
- Campa::Reader
- Defined in:
- lib/campa/reader.rb
Overview
Reads strings or files into Campa expressions. rubocop: disable Metrics/ClassLength
Instance Method Summary collapse
-
#initialize(input) ⇒ Reader
constructor
Given a String, a file pointer or any #getc, #eof? it allows fetch every valid Campa form from it.
-
#next ⇒ Object
Return the next Campa form available in the underlying io like object.
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
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
#next ⇒ Object
Return the next Campa form available in the underlying io like object.
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 |