Sha256: 0c2f66e51205226049b70bf6537c3a6d4c6983561adafcc1aedced57ba05b4ef

Contents?: true

Size: 888 Bytes

Versions: 4

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

module Leftovers
  module MatcherBuilders
    module StringPattern
      def self.build(match: nil, has_prefix: nil, has_suffix: nil) # rubocop:disable Metrics
        has_prefix = ::Regexp.escape(has_prefix) if has_prefix
        has_suffix = ::Regexp.escape(has_suffix) if has_suffix

        if match && has_prefix && has_suffix
          /\A(?=#{match}\z)(?=#{has_prefix}).*#{has_suffix}\z/
        elsif match && has_prefix
          /\A(?=#{match}\z)#{has_prefix}/
        elsif match && has_suffix
          /\A(?=#{match}\z).*#{has_suffix}\z/
        elsif match
          /\A#{match}\z/
        elsif has_prefix && has_suffix
          /\A(?=#{has_prefix}).*#{has_suffix}\z/
        elsif has_prefix
          /\A#{has_prefix}/
        elsif has_suffix
          /#{has_suffix}\z/
        else
          nil
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
leftovers-0.12.2 lib/leftovers/matcher_builders/string_pattern.rb
leftovers-0.12.1 lib/leftovers/matcher_builders/string_pattern.rb
leftovers-0.12.0 lib/leftovers/matcher_builders/string_pattern.rb
leftovers-0.11.2 lib/leftovers/matcher_builders/string_pattern.rb