class NameFinder::Buffer
Public Class Methods
new(string, position = 0)
click to toggle source
# File lib/name_finder/buffer.rb, line 3 def initialize(string, position = 0) @string = string @position = position @length = string.length end
Public Instance Methods
advance_by(n)
click to toggle source
# File lib/name_finder/buffer.rb, line 9 def advance_by(n) new(@position + n) end
advance_past(delimiter)
click to toggle source
# File lib/name_finder/buffer.rb, line 13 def advance_past(delimiter) p = (@position ... @length).find { |i| @string[i] == delimiter } if p new(p + 1) else new(@length) end end
at_end?()
click to toggle source
# File lib/name_finder/buffer.rb, line 22 def at_end? @position >= @length end
head()
click to toggle source
# File lib/name_finder/buffer.rb, line 26 def head @string[@position, 1] end
inspect(*args)
click to toggle source
# File lib/name_finder/buffer.rb, line 34 def inspect(*args) "<Buffer:#{@string[@position .. -1].inspect}>" end
rest()
click to toggle source
# File lib/name_finder/buffer.rb, line 30 def rest new(@position + 1) end
Private Instance Methods
new(position)
click to toggle source
# File lib/name_finder/buffer.rb, line 39 def new(position) Buffer.new(@string, position) end