Class: Sequence::Reversed
Overview
This class can be used to reverse the direction of operations on a given sequence. It has a separate position, independant of the original sequence’s.
Constant Summary
Constants inherited
from Sequence
SubSequence, VERSION
Instance Attribute Summary collapse
-
#pos ⇒ Object
readonly
def read1after @seq.read1before end def read1before @seq.read1after end.
-
#size ⇒ Object
readonly
def read1after @seq.read1before end def read1before @seq.read1after end.
Attributes inherited from Sequence
#last_match, #maxmatchlen
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Sequence
#+, #-, #<<, [], #[], #[]=, #_adjust_pos_on_change, #_default_maxmatchlen, #_delete_position, #_normalize_pos, #_parse_slice_args, #all_data, #append, #begin, #begin!, #check, #check_until, #checkback, #checkback_until, #close, #delete, #each, #empty?, #end, #end!, #exist?, #existback?, #first, #goto, #holding, #holding!, #holding?, #holding_position, #holding_position!, #holding_position?, #insert, #last, #length, #match?, #matchback?, #more_data?, #move, #move!, #nearbegin, #nearend, #new, #notify_change, #on_change_notify, #original__new, #overwrite, #pop, #pos=, #pos?, #position, #position=, #position?, #pred, #prepend, #prop, #read!, #read1, #readahead, #readahead1, #readback, #readback1, #readbehind, #readbehind1, #rest_size, #reversed, #shift, #skip, #skip_literal, #skip_until, #skip_until_literal, #skipback, #skipback_until, #slice, #slice!, #slice1, #slice1!, #subseq, #succ, #to_sequence, #was_data?, #write, #writeahead, #writeback, #writebehind
Constructor Details
#initialize(sequence, pos = 0) ⇒ Reversed
Returns a new instance of Reversed.
25
26
27
28
29
30
31
32
|
# File 'lib/sequence/reversed.rb', line 25
def initialize(sequence,pos=0)
@seq = sequence
@pos=pos
@size=sequence.size
extend @seq.like
@seq.on_change_notify self
end
|
Instance Attribute Details
#pos ⇒ Object
def read1after
@seq.read1before
end
def read1before
@seq.read1after
end
def skip1next
@seq.skip1prev
end
def skip1prev
@seq.skip1next
end
def skip1after
@seq.skip1before
end
def skip1before
@seq.skip1after
end
def delete1after
v0 = @seq.delete1before
v0 && @positions && _adjust_delete
v0
end
def delete1before
v0 = @seq.delete1after
v0 && @positions && _adjust_delete
v0
end
def delete1after?
v0 = @seq.delete1before?
v0.nil? || @positions && _adjust_delete
v0
end
def delete1before?
v0 = @seq.delete1after?
v0.nil? || @positions && _adjust_delete
v0
end
def write1next(v)
@seq.write1prev(v)
end
def write1prev(v)
@seq.write1next(v)
end
def write1after(v)
@seq.write1before(v)
end
def write1before(v)
@seq.write1after(v)
end
def write1next?(v)
@seq.write1prev?(v)
end
def write1prev?(v)
@seq.write1next?(v)
end
def write1after?(v)
@seq.write1before?(v)
end
def write1before?(v)
@seq.write1after?(v)
end
def insert1before(v)
@positions && _adjust_insert
@seq.insert1after(v)
end
def insert1after(v)
@positions && _adjust_insert
@seq.insert1before(v)
end
def scan1next(v)
@seq.scan1prev(v)
end
def scan1prev(v)
@seq.scan1next(v)
end
def modify1next(lookup)
@seq.modify1prev(lookup)
end
def modify1prev(lookup)
@seq.modify1next(lookup)
end
138
139
140
|
# File 'lib/sequence/reversed.rb', line 138
def pos
@pos
end
|
#size ⇒ Object
def read1after
@seq.read1before
end
def read1before
@seq.read1after
end
def skip1next
@seq.skip1prev
end
def skip1prev
@seq.skip1next
end
def skip1after
@seq.skip1before
end
def skip1before
@seq.skip1after
end
def delete1after
v0 = @seq.delete1before
v0 && @positions && _adjust_delete
v0
end
def delete1before
v0 = @seq.delete1after
v0 && @positions && _adjust_delete
v0
end
def delete1after?
v0 = @seq.delete1before?
v0.nil? || @positions && _adjust_delete
v0
end
def delete1before?
v0 = @seq.delete1after?
v0.nil? || @positions && _adjust_delete
v0
end
def write1next(v)
@seq.write1prev(v)
end
def write1prev(v)
@seq.write1next(v)
end
def write1after(v)
@seq.write1before(v)
end
def write1before(v)
@seq.write1after(v)
end
def write1next?(v)
@seq.write1prev?(v)
end
def write1prev?(v)
@seq.write1next?(v)
end
def write1after?(v)
@seq.write1before?(v)
end
def write1before?(v)
@seq.write1after?(v)
end
def insert1before(v)
@positions && _adjust_insert
@seq.insert1after(v)
end
def insert1after(v)
@positions && _adjust_insert
@seq.insert1before(v)
end
def scan1next(v)
@seq.scan1prev(v)
end
def scan1prev(v)
@seq.scan1next(v)
end
def modify1next(lookup)
@seq.modify1prev(lookup)
end
def modify1prev(lookup)
@seq.modify1next(lookup)
end
138
139
140
|
# File 'lib/sequence/reversed.rb', line 138
def size
@size
end
|
Class Method Details
.new(sequence, pos = 0) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/sequence/reversed.rb', line 15
def new(sequence,pos=0)
if Circular===sequence
Circular.new(new__no_circular(sequence.data,pos))
else
new__no_circular(sequence,pos)
end
end
|
.new__no_circular ⇒ Object
14
|
# File 'lib/sequence/reversed.rb', line 14
alias new__no_circular new
|
Instance Method Details
#_pos=(pos) ⇒ Object
139
140
141
|
# File 'lib/sequence/reversed.rb', line 139
def _pos=(pos)
@pos=pos
end
|
#change_notification(cu, first, oldsize, newsize) ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/sequence/reversed.rb', line 38
def change_notification(cu,first,oldsize,newsize)
assert cu==@seq
first=translate_pos(first+oldsize)
@pos =_adjust_pos_on_change((pos), first,oldsize,newsize)
@size+=newsize-oldsize
assert @size==@seq.size
notify_change(self, first,oldsize,newsize)
end
|
#closed? ⇒ Boolean
166
167
168
|
# File 'lib/sequence/reversed.rb', line 166
def closed?
super or @seq.closed?
end
|
#eof? ⇒ Boolean
162
163
164
|
# File 'lib/sequence/reversed.rb', line 162
def eof?
@pos>=@size
end
|
#modify(*args) ⇒ Object
153
154
155
156
157
158
159
160
|
# File 'lib/sequence/reversed.rb', line 153
def modify(*args)
first,len,only1=_parse_slice_args( *args[0..-2] )
first=@size-first-len
@seq.modify first, len, args.last.reverse
args.last
end
|
#new_data ⇒ Object
50
51
52
|
# File 'lib/sequence/reversed.rb', line 50
def new_data
@seq.new_data
end
|
#read(len) ⇒ Object
143
144
145
146
147
148
149
150
151
|
# File 'lib/sequence/reversed.rb', line 143
def read(len)
assert @pos>=0
assert @size>=@pos
start =@size-@pos-len
start<0 and start=0
result=@seq[start...@size-@pos] or return ""
@pos+=result.size
result.reverse
end
|
#reverse ⇒ Object
170
171
172
|
# File 'lib/sequence/reversed.rb', line 170
def reverse
@seq.position(0)
end
|
#translate_pos(pos) ⇒ Object
34
35
36
|
# File 'lib/sequence/reversed.rb', line 34
def translate_pos(pos)
@size-pos
end
|