Class: DeviceMap::Pattern

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/device_map/pattern.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keywords, device_id, priority) ⇒ Pattern

Returns a new instance of Pattern.



7
8
9
10
11
# File 'lib/device_map/pattern.rb', line 7

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

Instance Attribute Details

#device_idObject (readonly)

Returns the value of attribute device_id.



5
6
7
# File 'lib/device_map/pattern.rb', line 5

def device_id
  @device_id
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



5
6
7
# File 'lib/device_map/pattern.rb', line 5

def keywords
  @keywords
end

#priorityObject (readonly)

Returns the value of attribute priority.



5
6
7
# File 'lib/device_map/pattern.rb', line 5

def priority
  @priority
end

Instance Method Details

#<=>(other) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/device_map/pattern.rb', line 18

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

#==(other) ⇒ Object



26
27
28
29
30
# File 'lib/device_map/pattern.rb', line 26

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

#matches?(other_keywords) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/device_map/pattern.rb', line 13

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