Class: AsciidoctorVaped::Reader
- Inherits:
-
Object
- Object
- AsciidoctorVaped::Reader
- Defined in:
- lib/asciidoctor_vaped/reader.rb
Instance Attribute Summary collapse
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
Instance Method Summary collapse
- #eof? ⇒ Boolean
-
#initialize(source) ⇒ Reader
constructor
A new instance of Reader.
- #peek ⇒ Object
- #read ⇒ Object
- #read_delimited(delimiter) ⇒ Object
- #read_until_blank ⇒ Object
- #read_while ⇒ Object
- #skip_blank_lines ⇒ Object
Constructor Details
#initialize(source) ⇒ Reader
Returns a new instance of Reader.
7 8 9 10 |
# File 'lib/asciidoctor_vaped/reader.rb', line 7 def initialize(source) @lines = source.to_s.each_line(chomp: true).to_a @lineno = 0 end |
Instance Attribute Details
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
5 6 7 |
# File 'lib/asciidoctor_vaped/reader.rb', line 5 def lineno @lineno end |
Instance Method Details
#eof? ⇒ Boolean
12 13 14 |
# File 'lib/asciidoctor_vaped/reader.rb', line 12 def eof? lineno >= @lines.length end |
#peek ⇒ Object
16 17 18 |
# File 'lib/asciidoctor_vaped/reader.rb', line 16 def peek @lines[lineno] end |
#read ⇒ Object
20 21 22 23 24 |
# File 'lib/asciidoctor_vaped/reader.rb', line 20 def read return if eof? @lines[lineno].tap { @lineno += 1 } end |
#read_delimited(delimiter) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/asciidoctor_vaped/reader.rb', line 34 def read_delimited(delimiter) read lines = read_while { |line| line != delimiter } read if peek == delimiter lines end |
#read_until_blank ⇒ Object
30 31 32 |
# File 'lib/asciidoctor_vaped/reader.rb', line 30 def read_until_blank read_while { |line| line.strip != "" } end |
#read_while ⇒ Object
41 42 43 44 45 |
# File 'lib/asciidoctor_vaped/reader.rb', line 41 def read_while lines = [] lines << read while peek && yield(peek) lines end |
#skip_blank_lines ⇒ Object
26 27 28 |
# File 'lib/asciidoctor_vaped/reader.rb', line 26 def skip_blank_lines read while peek&.strip == "" end |