Sha256: bc4c69a49f4c9d9a92acf80e159c75eaf5f9c0512ed97f1275c64eb9173c5b20
Contents?: true
Size: 598 Bytes
Versions: 1
Compression:
Stored size: 598 Bytes
Contents
# frozen_string_literal: true module NameQ module Support class Suffix TOKEN = "%{index}" attr_reader :index def initialize(index, template: nil) @index = index @template = template || " (#{TOKEN})" end def strip(text) text.sub(regex, "") end def to_s @template % {index: index} end private def regex @_regex ||= begin first, last = @template.split(TOKEN) Regexp.new(Regexp.quote(first) + "[0-9]+" + Regexp.quote(last) + "$") end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nameq-0.0.3 | lib/nameq/support/suffix.rb |