Class: PSD::EngineData::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/psd/enginedata/text.rb

Overview

Sanitizes and helps with access to the document text.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Text

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



14
15
16
17
# File 'lib/psd/enginedata/text.rb', line 14

def initialize(text)
  @text = text.split("\n")
  @line = 0
end

Instance Attribute Details

#lineObject

The current line number in the document.



10
11
12
# File 'lib/psd/enginedata/text.rb', line 10

def line
  @line
end

#textObject (readonly)

The current document split by newlines into an array.



7
8
9
# File 'lib/psd/enginedata/text.rb', line 7

def text
  @text
end

Instance Method Details

#at_end?Boolean

Are we at the end of the document?

Returns:

  • (Boolean)


26
27
28
# File 'lib/psd/enginedata/text.rb', line 26

def at_end?
  @text[@line].nil?
end

#currentObject

Returns the current line stripped of any tabs and padding.



20
21
22
23
# File 'lib/psd/enginedata/text.rb', line 20

def current
  return nil if at_end?
  @text[@line].gsub(/\t/, "").strip
end

#lengthObject Also known as: size

Returns the number of lines in the document.



43
44
45
# File 'lib/psd/enginedata/text.rb', line 43

def length
  @text.length
end

#nextObject

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



38
39
40
# File 'lib/psd/enginedata/text.rb', line 38

def next
  @text[@line + 1]
end

#next!Object

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



31
32
33
34
# File 'lib/psd/enginedata/text.rb', line 31

def next!
  @line += 1
  current
end