Class: Stupidedi::Reader::AbstractInput
- Inherits:
-
Object
- Object
- Stupidedi::Reader::AbstractInput
- Includes:
- Inspect
- Defined in:
- lib/stupidedi/reader/input/abstract_input.rb
Overview
The String
and Array
refinements in lib/ruby
provide compatible
implementations of the abstract methods, so code written to target
this interface is backward-compatable with plain unwrapped String
and Array
values.
Provides an abstract interface for a positioned cursor within an element-based input stream. The main operations are implemented by the #take and #drop methods.
The DelegatedInput subclass wraps values that already implement the
interface, like String
and Array
. The FileInput subclass wraps
opened IO
streams like File
, and possibly others.
Direct Known Subclasses
Querying the Position collapse
-
#position ⇒ String
The file name, URI, etc that identifies the input stream.
Reading the Input collapse
-
#at(n)
abstract
Read a single element at the given index.
-
#index(element) ⇒ Integer
Returns the smallest
n
, where #at(n)
==element
. -
#take(n)
abstract
Read the first
n
elements.
Advancing the Cursor collapse
-
#drop(n) ⇒ AbstractInput
Advance the cursor forward
n
elements.
Testing the Input collapse
-
#==(other) ⇒ Boolean
abstract
True if
other
equals the remaining input. -
#defined_at?(n) ⇒ Boolean
abstract
True if the input contains enough elements such that #at
(n)
is defined. -
#empty? ⇒ Boolean
abstract
True if no elements remain in the input.
Methods included from Inspect
Instance Method Details
#==(other) ⇒ Boolean
True if other
equals the remaining input
134 |
# File 'lib/stupidedi/reader/input/abstract_input.rb', line 134 abstract :==, :args => %w(other) |
#at(n)
Read a single element at the given index. Result is undefined unless the input contains enough elements, which can be tested with #defined_at?
99 |
# File 'lib/stupidedi/reader/input/abstract_input.rb', line 99 abstract :at, :args => %w(n) |
#defined_at?(n) ⇒ Boolean
True if the input contains enough elements such that #at(n)
is
defined
126 |
# File 'lib/stupidedi/reader/input/abstract_input.rb', line 126 abstract :defined_at?, :args => %w(n) |
#drop(n) ⇒ AbstractInput
Advance the cursor forward n
elements
117 |
# File 'lib/stupidedi/reader/input/abstract_input.rb', line 117 abstract :drop, :args => %w(n) |
#empty? ⇒ Boolean
True if no elements remain in the input
129 |
# File 'lib/stupidedi/reader/input/abstract_input.rb', line 129 abstract :empty? |
#index(element) ⇒ Integer
Returns the smallest n
, where #at(n)
== element
107 |
# File 'lib/stupidedi/reader/input/abstract_input.rb', line 107 abstract :index, :args => %w(element) |
#position ⇒ String
The file name, URI, etc that identifies the input stream
60 |
# File 'lib/stupidedi/reader/input/abstract_input.rb', line 60 abstract :position |
#take(n)
Read the first n
elements
92 |
# File 'lib/stupidedi/reader/input/abstract_input.rb', line 92 abstract :take, :args => %w(n) |