Class: Rbzlib::Bytef
- Inherits:
-
Object
- Object
- Rbzlib::Bytef
- Defined in:
- lib/pr/rbzlib.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#offset ⇒ Object
Returns the value of attribute offset.
Instance Method Summary collapse
- #+(inc) ⇒ Object
- #-(dec) ⇒ Object
- #[](idx) ⇒ Object
- #[]=(idx, val) ⇒ Object
- #current ⇒ Object
- #get ⇒ Object
-
#initialize(buffer, offset = 0) ⇒ Bytef
constructor
A new instance of Bytef.
- #length ⇒ Object
- #set(val) ⇒ Object
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
#buffer ⇒ Object
Returns the value of attribute buffer.
150 151 152 |
# File 'lib/pr/rbzlib.rb', line 150 def buffer @buffer end |
#offset ⇒ Object
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 |
#current ⇒ Object
208 209 210 |
# File 'lib/pr/rbzlib.rb', line 208 def current @buffer[@offset..-1] end |
#get ⇒ Object
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 |
#length ⇒ Object
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 |