lib/linguist/heuristics.rb in github-linguist-7.10.0 vs lib/linguist/heuristics.rb in github-linguist-7.11.0

- old
+ new

@@ -30,10 +30,18 @@ end [] # No heuristics matched end + # Public: Get all heuristic definitions + # + # Returns an Array of heuristic objects. + def self.all + self.load() + @heuristics + end + # Internal: Load heuristics from 'heuristics.yml'. def self.load() if @heuristics.any? return end @@ -82,20 +90,32 @@ # Internal: Array of defined heuristics @heuristics = [] # Internal - def initialize(exts_and_langs, rules) - @exts_and_langs = exts_and_langs + def initialize(exts, rules) + @exts = exts @rules = rules end + # Internal: Return the heuristic's target extensions + def extensions + @exts + end + + # Internal: Return the heuristic's candidate languages + def languages + @rules.map do |rule| + [rule['language']].flatten(2).map { |name| Language[name] } + end.flatten.uniq + end + # Internal: Check if this heuristic matches the candidate filenames or # languages. def matches?(filename, candidates) filename = filename.downcase candidates = candidates.compact.map(&:name) - @exts_and_langs.any? { |ext| filename.end_with?(ext) } + @exts.any? { |ext| filename.end_with?(ext) } end # Internal: Perform the heuristic def call(data) matched = @rules.find do |rule|