Class: GemInfo::FuzzyMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_info/fuzzy_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, version) ⇒ FuzzyMatcher

Returns a new instance of FuzzyMatcher.



3
4
5
6
# File 'lib/gem_info/fuzzy_matcher.rb', line 3

def initialize(name, version)
  @name = name
  @version = version
end

Instance Method Details

#all_available_matchesObject



8
9
10
# File 'lib/gem_info/fuzzy_matcher.rb', line 8

def all_available_matches
  matches([])
end

#matches(specs) ⇒ Object



12
13
14
15
16
# File 'lib/gem_info/fuzzy_matcher.rb', line 12

def matches(specs)
  specs = matches_for(specs, :name, @name)
  specs = matches_for(specs, :version, @version) if @version
  specs
end

#matches_for(specs, attribute, value) ⇒ Object



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

def matches_for(specs, attribute, value)
  [:exact, :substring, :subsequence].each do |type|
    matches = send("#{type}_matches", specs, attribute, value)
    return matches if !matches.empty?
  end
  []
end