diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index d6488c7f..574b280c 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -4,7 +4,7 @@ module Linguist ACTIVE = true def self.call(blob, languages) - find_by_heuristics(blob.data, langauges.map(&:name)) + find_by_heuristics(blob.data, languages.map(&:name)) end # Public: Given an array of String language names, diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index c4194ea2..40570356 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -10,6 +10,9 @@ require 'linguist/heuristics' require 'linguist/samples' require 'linguist/file_blob' require 'linguist/blob_helper' +require 'linguist/strategy/filename' +require 'linguist/strategy/shebang' +require 'linguist/strategy/classifier' module Linguist # Language names that are recognizable by GitHub. Defined languages @@ -91,10 +94,6 @@ module Linguist language end - require 'linguist/strategy/filename' - require 'linguist/strategy/shebang' - require 'linguist/strategy/classifier' - STRATEGIES = [ Linguist::Strategy::Filename, Linguist::Strategy::Shebang, @@ -112,17 +111,16 @@ module Linguist # Bail early if the blob is binary or empty. return nil if blob.likely_binary? || blob.binary? || blob.empty? - # Call each strategy until 0 or 1 candidates are returned + # Call each strategy until one candidate is returned STRATEGIES.reduce([]) do |languages, strategy| - if candidates = strategy.call(blob, languages) - if candidates.size > 1 - # More than one candidate was found, return them for the next strategy - candidates - else - # 1 or 0 candidates, stop trying strategies - break candidates - end + candidates = strategy.call(blob, languages) + if candidates.size == 1 + return candidates.first + elsif candidates.size > 1 + # More than one candidate was found, pass them to the next strategy + candidates else + # Strategy couldn't find any candidates, so pass on the original list languages end end.first diff --git a/lib/linguist/strategy/classifier.rb b/lib/linguist/strategy/classifier.rb index 0bdbae69..86a516b4 100644 --- a/lib/linguist/strategy/classifier.rb +++ b/lib/linguist/strategy/classifier.rb @@ -3,7 +3,7 @@ module Linguist # Detect language using the bayesian classifier class Classifier def self.call(blob, languages) - Linguist::Classifier.classify(Samples.cache, blob.data, laguages.map(&:name)).map do |name| + Linguist::Classifier.classify(Samples.cache, blob.data, languages.map(&:name)).map do |name, _| # Return the actual Language object based of the string language name (i.e., first element of `#classify`) Language[name] end