Class: PSD::EngineData::Text
- Inherits:
-
Object
- Object
- PSD::EngineData::Text
- Defined in:
- lib/psd/enginedata/text.rb
Overview
Sanitizes and helps with access to the document text.
Instance Attribute Summary collapse
-
#line ⇒ Object
The current line number in the document.
-
#text ⇒ Object
readonly
The current document split by newlines into an array.
Instance Method Summary collapse
-
#at_end? ⇒ Boolean
Are we at the end of the document?.
-
#current ⇒ Object
Returns the current line stripped of any tabs and padding.
-
#initialize(text) ⇒ Text
constructor
Stores the document as a newline-split array and initializes the current line to 0.
-
#length ⇒ Object
(also: #size)
Returns the number of lines in the document.
-
#next ⇒ Object
Peeks at the next line in the document without moving the line pointer.
-
#next! ⇒ Object
Moves the line pointer to the next line and returns it.
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
#line ⇒ Object
The current line number in the document.
10 11 12 |
# File 'lib/psd/enginedata/text.rb', line 10 def line @line end |
#text ⇒ Object (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?
26 27 28 |
# File 'lib/psd/enginedata/text.rb', line 26 def at_end? @text[@line].nil? end |
#current ⇒ Object
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 |
#length ⇒ Object 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 |
#next ⇒ Object
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 |