Module: FuzzyURL::Matching::ClassMethods

Defined in:
lib/fuzzy_url/matching.rb

Instance Method Summary collapse

Instance Method Details

#match_hash(mask, url) ⇒ Object

Compares a URL mask hash with a URL hash. Returns nil on negative match, and an integer match score otherwise. This match score is higher for more specific matches.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fuzzy_url/matching.rb', line 15

def match_hash(mask, url)
  score = 0
  tally = Proc.new {|x| return nil unless x; score += x}

  tally.call match_hostnames(mask[:hostname], url[:hostname])
  tally.call match_protocols_and_ports(mask, url)
  tally.call match_paths(mask[:path], url[:path])
  tally.call fuzzy_match(mask[:query], url[:query])
  tally.call fuzzy_match(mask[:username], url[:username])
  tally.call fuzzy_match(mask[:password], url[:password])
  tally.call fuzzy_match(mask[:fragment], url[:fragment])
end