Class: PageMagic::Comparator::Fuzzy

Inherits:
PageMagic::Comparator show all
Defined in:
lib/page_magic/comparator/fuzzy.rb

Overview

class Fuzzy - used for modeling and comparing components that are 'fuzzy' i.e. respond to =~ e.g. a Regexp

Instance Attribute Summary

Attributes inherited from PageMagic::Comparator

#comparator, #fuzzy

Instance Method Summary collapse

Methods inherited from PageMagic::Comparator

#==, for, #fuzzy?, #to_s

Constructor Details

#initialize(comparator) ⇒ Fuzzy

Returns a new instance of Fuzzy.



7
8
9
# File 'lib/page_magic/comparator/fuzzy.rb', line 7

def initialize(comparator)
  super(comparator, true)
end

Instance Method Details

#<=>(other) ⇒ Object



15
16
17
18
19
20
# File 'lib/page_magic/comparator/fuzzy.rb', line 15

def <=>(other)
  return -1 if other.is_a?(Null)
  return 1 unless other.fuzzy?

  0
end

#match?(value) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/page_magic/comparator/fuzzy.rb', line 11

def match?(value)
  comparator =~ value ? true : false
end