Sha256: c3ba3ff4084e2ab4e788b8da28234491ff0ffad291a5e745dc4b89d0d675e4a4

Contents?: true

Size: 788 Bytes

Versions: 12

Compression:

Stored size: 788 Bytes

Contents

# frozen_string_literal: true

require_relative 'comparator/fuzzy'
require_relative 'comparator/literal'
require_relative 'comparator/parameter_map'
require_relative 'comparator/null'

module PageMagic
  # class Comparator - used for comparing components used for mapping pages
  class Comparator
    class << self
      def for(comparator)
        klass = { Regexp => Fuzzy, Hash => ParameterMap, NilClass => Null }.fetch(comparator.class, Literal)
        klass.new(comparator)
      end
    end

    attr_reader :comparator, :fuzzy

    def initialize(comparator, fuzzy)
      @comparator = comparator
      @fuzzy = fuzzy
    end

    def fuzzy?
      fuzzy
    end

    def to_s
      comparator.to_s
    end

    def ==(other)
      comparator == other.comparator
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
page_magic-2.0.13 lib/page_magic/comparator.rb
page_magic-2.0.12 lib/page_magic/comparator.rb
page_magic-2.0.11 lib/page_magic/comparator.rb
page_magic-2.0.10 lib/page_magic/comparator.rb
page_magic-2.0.9 lib/page_magic/comparator.rb
page_magic-2.0.6 lib/page_magic/comparator.rb
page_magic-2.0.5 lib/page_magic/comparator.rb
page_magic-2.0.4 lib/page_magic/comparator.rb
page_magic-2.0.3 lib/page_magic/comparator.rb
page_magic-2.0.2 lib/page_magic/comparator.rb
page_magic-2.0.1 lib/page_magic/comparator.rb
page_magic-2.0.0 lib/page_magic/comparator.rb