Class: Rbzlib::Bytef

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

Direct Known Subclasses

Posf

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer, offset = 0) ⇒ Bytef

Returns a new instance of Bytef.



152
153
154
155
156
157
158
159
160
# File 'lib/pr/rbzlib.rb', line 152

def initialize(buffer, offset=0)
  if [String, Array].include?(buffer.class)
    @buffer = buffer
    @offset = offset
  else
    @buffer = buffer.buffer
    @offset = offset
  end
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



150
151
152
# File 'lib/pr/rbzlib.rb', line 150

def buffer
  @buffer
end

#offsetObject

Returns the value of attribute offset.



150
151
152
# File 'lib/pr/rbzlib.rb', line 150

def offset
  @offset
end

Instance Method Details

#+(inc) ⇒ Object



166
167
168
169
# File 'lib/pr/rbzlib.rb', line 166

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

#-(dec) ⇒ Object



171
172
173
174
# File 'lib/pr/rbzlib.rb', line 171

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

#[](idx) ⇒ Object



176
177
178
179
180
181
182
# File 'lib/pr/rbzlib.rb', line 176

def [](idx)
  if @buffer.is_a?(String)
    @buffer[idx + @offset].ord
  else
    @buffer[idx + @offset]
  end
end

#[]=(idx, val) ⇒ Object



184
185
186
187
188
189
190
# File 'lib/pr/rbzlib.rb', line 184

def []=(idx, val)
  if @buffer.is_a?(String) && val.is_a?(Fixnum)
    @buffer[idx + @offset] = val.chr
  else
    @buffer[idx + @offset] = val
  end
end

#currentObject



208
209
210
# File 'lib/pr/rbzlib.rb', line 208

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

#getObject



192
193
194
195
196
197
198
# File 'lib/pr/rbzlib.rb', line 192

def get()
  if @buffer.is_a?(String)
    @buffer[@offset].ord
  else
    @buffer[@offset]
  end
end

#lengthObject



162
163
164
# File 'lib/pr/rbzlib.rb', line 162

def length
  @buffer.length
end

#set(val) ⇒ Object



200
201
202
203
204
205
206
# File 'lib/pr/rbzlib.rb', line 200

def set(val)
  if @buffer.is_a?(String) && val.is_a?(Fixnum)
    @buffer[@offset] = val.chr
  else
    @buffer[@offset] = val
  end
end