class Raabro::Input

Attributes

offset[RW]
options[R]
string[RW]

Public Class Methods

new(string, offset=0, options={}) click to toggle source
# File lib/raabro.rb, line 12
def initialize(string, offset=0, options={})

  @string = string
  @offset = offset.is_a?(Hash) ? 0 : offset
  @options = offset.is_a?(Hash) ? offset : options
end

Public Instance Methods

at(i) click to toggle source
# File lib/raabro.rb, line 36
def at(i)

  @string[i, 1]
end
match(str_or_regex) click to toggle source
# File lib/raabro.rb, line 19
def match(str_or_regex)

  if str_or_regex.is_a?(Regexp)
    m = @string[@offset..-1].match(str_or_regex)
    m && (m.offset(0).first == 0) ? m[0].length : false
  else # String or whatever responds to #to_s
    s = str_or_regex.to_s
    l = s.length
    @string[@offset, l] == s ? l : false
  end
end
tring(l=-1) click to toggle source
# File lib/raabro.rb, line 31
def tring(l=-1)

  l < 0 ? @string[@offset..l] : @string[@offset, l]
end