Class: ValueBuffer
- Inherits:
-
Object
- Object
- ValueBuffer
- Defined in:
- lib/mad_clibs/util/value_buffer.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
- #<<(c) ⇒ Object
- #backspace ⇒ Object
-
#initialize(s = "") ⇒ ValueBuffer
constructor
A new instance of ValueBuffer.
- #left ⇒ Object
- #right ⇒ Object
- #value ⇒ Object
- #value=(s) ⇒ Object
Constructor Details
#initialize(s = "") ⇒ ValueBuffer
Returns a new instance of ValueBuffer.
4 5 6 |
# File 'lib/mad_clibs/util/value_buffer.rb', line 4 def initialize(s="") self.value = s end |
Instance Attribute Details
#position ⇒ Object (readonly)
Returns the value of attribute position.
2 3 4 |
# File 'lib/mad_clibs/util/value_buffer.rb', line 2 def position @position end |
Instance Method Details
#<<(c) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/mad_clibs/util/value_buffer.rb', line 21 def << c if @position < 0 @position = 0 end @buffer.insert(@position,c) @position += 1 end |
#backspace ⇒ Object
16 17 18 19 |
# File 'lib/mad_clibs/util/value_buffer.rb', line 16 def backspace @buffer = @buffer[0..-2] left end |
#left ⇒ Object
8 9 10 |
# File 'lib/mad_clibs/util/value_buffer.rb', line 8 def left @position -= 1 if @position >= 0 end |
#right ⇒ Object
12 13 14 |
# File 'lib/mad_clibs/util/value_buffer.rb', line 12 def right @position += 1 if @position < value.length end |
#value ⇒ Object
34 35 36 |
# File 'lib/mad_clibs/util/value_buffer.rb', line 34 def value @buffer end |
#value=(s) ⇒ Object
29 30 31 32 |
# File 'lib/mad_clibs/util/value_buffer.rb', line 29 def value=(s) @buffer = s.dup @position = -1 end |