class PSD::EngineData::Text

Sanitizes and helps with access to the document text.

Attributes

line[RW]

The current line number in the document.

text[R]

The current document split by newlines into an array.

Public Class Methods

new(text) click to toggle source

Stores the document as a newline-split array and initializes the current line to 0.

# File lib/psd/enginedata/text.rb, line 13
def initialize(text)
  @text = text.split("\n")
  @line = 0
end

Public Instance Methods

at_end?() click to toggle source

Are we at the end of the document?

# File lib/psd/enginedata/text.rb, line 25
def at_end?
  @text[@line].nil?
end
current() click to toggle source

Returns the current line stripped of any tabs and padding.

# File lib/psd/enginedata/text.rb, line 19
def current
  return nil if at_end?
  @text[@line].gsub(/\t/, "").strip
end
length() click to toggle source

Returns the number of lines in the document.

# File lib/psd/enginedata/text.rb, line 42
def length
  @text.length
end
Also aliased as: size
next() click to toggle source

Peeks at the next line in the document without moving the line pointer.

# File lib/psd/enginedata/text.rb, line 37
def next
  @text[@line + 1]
end
next!() click to toggle source

Moves the line pointer to the next line and returns it.

# File lib/psd/enginedata/text.rb, line 30
def next!
  @line += 1
  current
end
size()
Alias for: length