Class: Rbzlib::Bytef_str
- Inherits:
-
Object
- Object
- Rbzlib::Bytef_str
- Defined in:
- lib/pr/rbzlib/bytef_str.rb
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_str
constructor
A new instance of Bytef_str.
- #length ⇒ Object
- #set(val) ⇒ Object
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
#buffer ⇒ Object
Returns the value of attribute buffer.
5 6 7 |
# File 'lib/pr/rbzlib/bytef_str.rb', line 5 def buffer @buffer end |
#offset ⇒ Object
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 |
#current ⇒ Object
48 49 50 |
# File 'lib/pr/rbzlib/bytef_str.rb', line 48 def current @buffer[@offset..-1] end |
#get ⇒ Object
40 41 42 |
# File 'lib/pr/rbzlib/bytef_str.rb', line 40 def get @buffer.getbyte(@offset) end |
#length ⇒ Object
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 |