Class: Rbzlib::Bytef_str

Inherits:
Object
  • Object
show all
Defined in:
lib/pr/rbzlib/bytef_str.rb

Direct Known Subclasses

Bytef_arr, Posf

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer, offset = 0) ⇒ Bytef_str

Returns a new instance of Bytef_str.



7
8
9
10
11
12
13
14
15
16
# File 'lib/pr/rbzlib/bytef_str.rb', line 7

def initialize(buffer, offset = 0)
  if buffer.class == String
    @buffer = buffer
    @offset = offset
    @buffer.force_encoding('ASCII-8BIT')
  else
    @buffer = buffer.buffer
    @offset = offset
  end
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



5
6
7
# File 'lib/pr/rbzlib/bytef_str.rb', line 5

def buffer
  @buffer
end

#offsetObject

Returns the value of attribute offset.



5
6
7
# File 'lib/pr/rbzlib/bytef_str.rb', line 5

def offset
  @offset
end

Instance Method Details

#+(inc) ⇒ Object



22
23
24
25
# File 'lib/pr/rbzlib/bytef_str.rb', line 22

def +(inc)
  @offset += inc
  self
end

#-(dec) ⇒ Object



27
28
29
30
# File 'lib/pr/rbzlib/bytef_str.rb', line 27

def -(dec)
  @offset -= dec
  self
end

#[](idx) ⇒ Object



32
33
34
# File 'lib/pr/rbzlib/bytef_str.rb', line 32

def [](idx)
  @buffer.getbyte(idx + @offset)
end

#[]=(idx, val) ⇒ Object



36
37
38
# File 'lib/pr/rbzlib/bytef_str.rb', line 36

def []=(idx, val)
  @buffer.setbyte(idx + @offset, val.ord)
end

#currentObject



48
49
50
# File 'lib/pr/rbzlib/bytef_str.rb', line 48

def current
  @buffer[@offset..-1]
end

#getObject



40
41
42
# File 'lib/pr/rbzlib/bytef_str.rb', line 40

def get
  @buffer.getbyte(@offset)
end

#lengthObject



18
19
20
# File 'lib/pr/rbzlib/bytef_str.rb', line 18

def length
  @buffer.length
end

#set(val) ⇒ Object



44
45
46
# File 'lib/pr/rbzlib/bytef_str.rb', line 44

def set(val)
  @buffer.setbyte(@offset, val.ord)
end