Sha256: e06e7c57eb4f877e454b55f2c1a0a59d2f5ccca8592ed8693b7ae10cd254d60b

Contents?: true

Size: 698 Bytes

Versions: 3

Compression:

Stored size: 698 Bytes

Contents

module DeviceMap
  class Pattern
    include Comparable

    attr_reader :keywords, :device_id, :priority

    def initialize(keywords, device_id, priority)
      @keywords = Keyword.normalize(Array(keywords))
      @device_id = device_id
      @priority = priority
    end

    def matches?(other_keywords)
      diff = keywords - other_keywords
      diff.empty?
    end

    def <=>(other)
      if priority == other.priority
        keywords.join.size <=> other.keywords.join.size
      else
        priority <=> other.priority
      end
    end

    def ==(other)
      keywords == other.keywords &&
        device_id == other.device_id &&
        priority == other.priority
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
device_map-0.1.2 lib/device_map/pattern.rb
device_map-0.1.1 lib/device_map/pattern.rb
device_map-0.1.0 lib/device_map/pattern.rb