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.



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

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.



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

def buffer
  @buffer
end

#offsetObject

Returns the value of attribute offset.



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

def offset
  @offset
end

Instance Method Details

#+(inc) ⇒ Object



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

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

#-(dec) ⇒ Object



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

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

#[](idx) ⇒ Object



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

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

#[]=(idx, val) ⇒ Object



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

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



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

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

#getObject



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

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

#lengthObject



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

def length
   @buffer.length
end

#set(val) ⇒ Object



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

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