Sha256: 2bf678ad757d6f22586917d56b0e0692d3a204d497cde919c16951339b0a7e14
Contents?: true
Size: 633 Bytes
Versions: 1
Compression:
Stored size: 633 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.1 | lib/nameq/support/suffix.rb |