Class: RDocF95::Markup::Lines

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rdoc-f95/markup/lines.rb

Overview

A container for all the lines.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ Lines

Returns a new instance of Lines.



96
97
98
99
# File 'lib/rdoc-f95/markup/lines.rb', line 96

def initialize(lines)
  @lines = lines
  rewind
end

Instance Attribute Details

#linesObject (readonly)

:nodoc:



94
95
96
# File 'lib/rdoc-f95/markup/lines.rb', line 94

def lines
  @lines
end

Instance Method Details

#as_textObject



141
142
143
# File 'lib/rdoc-f95/markup/lines.rb', line 141

def as_text
  @lines.map {|l| l.text}.join("\n")
end

#delete(a_line) ⇒ Object



131
132
133
# File 'lib/rdoc-f95/markup/lines.rb', line 131

def delete(a_line)
  a_line.deleted = true
end

#eachObject



105
106
107
108
109
# File 'lib/rdoc-f95/markup/lines.rb', line 105

def each
  @lines.each do |line|
    yield line unless line.deleted
  end
end

#empty?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/rdoc-f95/markup/lines.rb', line 101

def empty?
  @lines.size.zero?
end

#line_typesObject



145
146
147
# File 'lib/rdoc-f95/markup/lines.rb', line 145

def line_types
  @lines.map {|l| l.type }
end

#nextObject



119
120
121
122
123
124
125
# File 'lib/rdoc-f95/markup/lines.rb', line 119

def next
  begin
    res = @lines[@nextline]
    @nextline += 1 if @nextline < @lines.size
  end while res and res.deleted and @nextline < @lines.size
  res
end

#normalizeObject



135
136
137
138
139
# File 'lib/rdoc-f95/markup/lines.rb', line 135

def normalize
  margin = @lines.collect{|l| l.leading_spaces}.min
  margin = 0 if margin == :INFINITY
  @lines.each {|line| line.strip_leading(margin) } if margin > 0
end

#rewindObject

def [](index)

  @lines[index]
end


115
116
117
# File 'lib/rdoc-f95/markup/lines.rb', line 115

def rewind
  @nextline = 0
end

#ungetObject



127
128
129
# File 'lib/rdoc-f95/markup/lines.rb', line 127

def unget
  @nextline -= 1
end