class NameQ::Support::Suffix

Constants

TOKEN

Attributes

index[R]

Public Class Methods

new(index, template: nil) click to toggle source
# File lib/nameq/support/suffix.rb, line 9
def initialize(index, template: nil)
  @index = index
  @template = template || " (#{TOKEN})"
end

Public Instance Methods

strip(text) click to toggle source
# File lib/nameq/support/suffix.rb, line 14
def strip(text)
  text.sub(regex, "")
end
to_s() click to toggle source
# File lib/nameq/support/suffix.rb, line 18
def to_s
  @template % {index: index}
end

Private Instance Methods

regex() click to toggle source
# File lib/nameq/support/suffix.rb, line 24
def regex
  @_regex ||= begin
    first, last = @template.split(TOKEN)
    Regexp.new(Regexp.quote(first) + "[0-9]+" + Regexp.quote(last) + "$")
  end
end