Class: ValueBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/mad_clibs/util/value_buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s = "") ⇒ ValueBuffer



4
5
6
# File 'lib/mad_clibs/util/value_buffer.rb', line 4

def initialize(s="")
  self.value = s
end

Instance Attribute Details

#positionObject (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

#backspaceObject



16
17
18
19
# File 'lib/mad_clibs/util/value_buffer.rb', line 16

def backspace
  @buffer = @buffer[0..-2]
  left
end

#leftObject



8
9
10
# File 'lib/mad_clibs/util/value_buffer.rb', line 8

def left
  @position -= 1 if @position >= 0
end

#rightObject



12
13
14
# File 'lib/mad_clibs/util/value_buffer.rb', line 12

def right
  @position += 1 if @position < value.length
end

#valueObject



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