class String

Public Instance Methods

after(substr) click to toggle source
# File lib/dohutil/core_ext/string.rb, line 18
def after(substr)
  loc = index(substr)
  return nil if loc.nil?
  mid(loc + substr.size)
end
before(substr) click to toggle source
# File lib/dohutil/core_ext/string.rb, line 30
def before(substr)
  loc = index(substr)
  return nil if loc.nil?
  firstn(loc)
end
firstn(limit) click to toggle source
# File lib/dohutil/core_ext/string.rb, line 2
def firstn(limit)
  return nil if limit < 0
  return '' if limit == 0
  slice(Range.new(0, limit - 1))
end
lastn(limit) click to toggle source
# File lib/dohutil/core_ext/string.rb, line 8
def lastn(limit)
  return nil if limit < 0
  return '' if limit == 0
  slice(Range.new(-limit, -1)) || self
end
mid(first, count = nil) click to toggle source
# File lib/dohutil/core_ext/string.rb, line 14
def mid(first, count = nil)
  slice(first, count || (size - first))
end
rafter(substr) click to toggle source
# File lib/dohutil/core_ext/string.rb, line 24
def rafter(substr)
  loc = rindex(substr)
  return nil if loc.nil?
  mid(loc + substr.size)
end
rbefore(substr) click to toggle source
# File lib/dohutil/core_ext/string.rb, line 36
def rbefore(substr)
  loc = rindex(substr)
  return nil if loc.nil?
  firstn(loc)
end