Class: Stupidedi::Reader::DelegatedInput
- Inherits:
-
AbstractInput
- Object
- AbstractInput
- Stupidedi::Reader::DelegatedInput
- Defined in:
- lib/stupidedi/reader/input/delegated_input.rb
Querying the Position collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
Querying the Position collapse
-
#position ⇒ String
The file name, URI, etc that identifies the input stream.
Advancing the Cursor collapse
-
#drop(n) ⇒ AbstractInput
Advance the cursor forward ‘n` elements.
Instance Method Summary collapse
-
#initialize(delegate, offset = 0, line = 1, column = 1) ⇒ DelegatedInput
constructor
A new instance of DelegatedInput.
- #pretty_print(q) ⇒ void
Methods inherited from AbstractInput
Methods included from Inspect
Constructor Details
#initialize(delegate, offset = 0, line = 1, column = 1) ⇒ DelegatedInput
Returns a new instance of DelegatedInput.
9 10 11 12 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 9 def initialize(delegate, offset = 0, line = 1, column = 1) @delegate, @offset, @line, @column = delegate, offset, line, column end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
24 25 26 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 24 def column @column end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
21 22 23 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 21 def line @line end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
18 19 20 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 18 def offset @offset end |
Instance Method Details
#drop(n) ⇒ AbstractInput
Advance the cursor forward ‘n` elements
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 49 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 ⇒ String
The file name, URI, etc that identifies the input stream
27 28 29 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 27 def position Position.new(@offset, @line, @column, nil) end |
#pretty_print(q) ⇒ void
This method returns an undefined value.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/stupidedi/reader/input/delegated_input.rb', line 87 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 |