Class: Sequence::UseData

Inherits:
Sequence show all
Defined in:
lib/sequence/usedata.rb

Overview

define #read in terms of #data and @pos. #data must support #[]

Direct Known Subclasses

Indexed, Position

Constant Summary

Constants inherited from Sequence

SubSequence, VERSION

Instance Attribute Summary

Attributes inherited from Sequence

#last_match, #maxmatchlen

Instance Method Summary collapse

Methods inherited from Sequence

#+, #-, #<<, [], #[], #[]=, #_adjust_pos_on_change, #_default_maxmatchlen, #_delete_position, #_normalize_pos, #_parse_slice_args, #_pos=, #all_data, #append, #begin, #begin!, #check, #check_until, #checkback, #checkback_until, #close, #closed?, #delete, #each, #empty?, #end, #end!, #eof?, #exist?, #existback?, #first, #goto, #holding, #holding!, #holding?, #holding_position, #holding_position!, #holding_position?, #initialize, #insert, #last, #length, #match?, #matchback?, #modify, #more_data?, #move, #move!, #nearbegin, #nearend, #new, #notify_change, #on_change_notify, #original__new, #overwrite, #pop, #pos, #pos=, #pos?, #position, #position=, #position?, #pred, #prepend, #prop, #read!, #read1, #readahead1, #readback1, #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

This class inherits a constructor from Sequence

Instance Method Details

#read(len) ⇒ Object



9
10
11
12
13
# File 'lib/sequence/usedata.rb', line 9

def read(len)
  result=readahead(len)
  @pos+=result.size
  result
end

#readahead(len) ⇒ Object



21
22
23
# File 'lib/sequence/usedata.rb', line 21

def readahead(len)
  @data[@pos,len] 
end

#readback(len) ⇒ Object



15
16
17
18
19
# File 'lib/sequence/usedata.rb', line 15

def readback(len)
  result=readbehind(len)
  @pos-=result.size
  result
end

#readbehind(len) ⇒ Object



25
26
27
28
# File 'lib/sequence/usedata.rb', line 25

def readbehind(len)
  len>@pos and len=@pos
  @data[@pos-len,len] 
end

#sizeObject



31
# File 'lib/sequence/usedata.rb', line 31

def size; data.size end