Class: Stupidedi::Reader::DelegatedInput
- Inherits:
-
AbstractInput
- Object
- AbstractInput
- Stupidedi::Reader::DelegatedInput
- Defined in:
- lib/stupidedi/reader/input/delegated_input.rb
Querying the Position (collapse)
-
- (Integer) column
readonly
The column of the current position.
-
- (Integer) line
readonly
The line of the current position.
-
- (Integer) offset
readonly
The current position as the number of elements previously read.
Querying the Position (collapse)
-
- (Position) position
The Position value that describes the position of the input stream.
Advancing the Cursor (collapse)
-
- (AbstractInput) drop(n)
Advance the cursor forward
nelements.
Instance Method Summary (collapse)
-
- (DelegatedInput) initialize(delegate, offset = 0, line = 1, column = 1)
constructor
A new instance of DelegatedInput.
- - pretty_print(q)
Methods inherited from AbstractInput
Methods included from Inspect
Constructor Details
- (DelegatedInput) initialize(delegate, offset = 0, line = 1, column = 1)
A new instance of DelegatedInput
6 7 8 9 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 6 def initialize(delegate, offset = 0, line = 1, column = 1) @delegate, @offset, @line, @column = delegate, offset, line, column end |
Instance Attribute Details
- (Integer) column (readonly)
The column of the current position. The column resets to 1 each time
a newline is read
21 22 23 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 21 def column @column end |
- (Integer) line (readonly)
The line of the current position
18 19 20 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 18 def line @line end |
- (Integer) offset (readonly)
The current position as the number of elements previously read
15 16 17 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 15 def offset @offset end |
Instance Method Details
- (AbstractInput) drop(n)
Advance the cursor forward n elements
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 44 def drop(n) raise ArgumentError, "n must be positive" unless n >= 0 suffix = @delegate.drop(n) prefix = @delegate.take(n) length = prefix.length count = prefix.count("\n") column = unless count.zero? length - prefix.rindex("\n") else @column + length end copy(:delegate => suffix, :offset => @offset + length, :line => @line + count, :column => column) end |
- (Position) position
The Position value that describes the position of the input stream
24 25 26 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 24 def position Position.new(@offset, @line, @column, nil) end |
- pretty_print(q)
This method returns an undefined value.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 81 def pretty_print(q) q.text("DelegateInput") q.group(2, "(", ")") do preview = @delegate.take(4) preview = if preview.empty? "EOF" elsif preview.length <= 3 preview.inspect else (preview.take(3) << "...").inspect end q.text preview q.text " at line #{@line}, column #{@column}, offset #{@offset}" end end |