Class: TemplatePage::LineReader

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc/template.rb

Overview

####### Simple class to read lines out of a string

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ LineReader

we're initialized with an array of lines



87
88
89
# File 'lib/rdoc/template.rb', line 87

def initialize(lines)
  @lines = lines
end

Instance Method Details

#dupObject

Return a copy of ourselves that can be modified without affecting us



112
113
114
# File 'lib/rdoc/template.rb', line 112

def dup
  LineReader.new(@lines.dup)
end

#readObject

read the next line



92
93
94
# File 'lib/rdoc/template.rb', line 92

def read
  @lines.shift
end

#read_up_to(pattern) ⇒ Object

Return a list of lines up to the line that matches a pattern. That last line is discarded.



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rdoc/template.rb', line 98

def read_up_to(pattern)
  res = []
  while line = read
    if pattern.match(line)
      return LineReader.new(res) 
    else
      res << line
    end
  end
  raise "Missing end tag in template: #{pattern.source}"
end