Class: AsciidoctorVaped::Reader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#linenoObject (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

Returns:

  • (Boolean)


12
13
14
# File 'lib/asciidoctor_vaped/reader.rb', line 12

def eof?
  lineno >= @lines.length
end

#peekObject



16
17
18
# File 'lib/asciidoctor_vaped/reader.rb', line 16

def peek
  @lines[lineno]
end

#readObject



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_blankObject



30
31
32
# File 'lib/asciidoctor_vaped/reader.rb', line 30

def read_until_blank
  read_while { |line| line.strip != "" }
end

#read_whileObject



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_linesObject



26
27
28
# File 'lib/asciidoctor_vaped/reader.rb', line 26

def skip_blank_lines
  read while peek&.strip == ""
end