mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-02-10 18:29:34 +00:00
Extract strategies for detecting the language
This commit is contained in:
12
lib/linguist/strategy/classifier.rb
Normal file
12
lib/linguist/strategy/classifier.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module Linguist
|
||||
module Strategy
|
||||
class Classifier
|
||||
def self.call(blob, languages)
|
||||
Linguist::Classifier.classify(Samples.cache, blob.data, possible_language_names).map do |name|
|
||||
# Return the actual Language object based of the string language name (i.e., first element of `#classify`)
|
||||
Language[name]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
module Linguist
|
||||
module Strategy
|
||||
class Filename
|
||||
def call(blob)
|
||||
def self.call(blob, _)
|
||||
name = blob.name.to_s
|
||||
|
||||
# A bit of an elegant hack. If the file is executable but extensionless,
|
||||
@@ -13,7 +13,7 @@ module Linguist
|
||||
end
|
||||
|
||||
# First try to find languages that match based on filename.
|
||||
possible_languages = Language.find_by_filename(name)
|
||||
Language.find_by_filename(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
9
lib/linguist/strategy/shebang.rb
Normal file
9
lib/linguist/strategy/shebang.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module Linguist
|
||||
module Strategy
|
||||
class Shebang
|
||||
def self.call(blob, _)
|
||||
Language.find_by_shebang(blob.data)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user