Class: Prettyp::LanguageDetectionService
- Inherits:
-
Object
- Object
- Prettyp::LanguageDetectionService
- Defined in:
- lib/prettyp/language_detection_service.rb
Constant Summary collapse
- POSSIBLE_LANGUAGE_NAMES =
Our supported languages
['XML', 'Ruby', 'JSON', 'JavaScript', 'HTML']
Instance Method Summary collapse
Instance Method Details
#detect_from_file(file) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/prettyp/language_detection_service.rb', line 8 def detect_from_file file file_blob = Linguist::FileBlob.new(file.path) language = file_blob.language return format_language_key(language.name) if language detect_from_input(file_blob.data) end |
#detect_from_input(input) ⇒ Object
16 17 18 19 |
# File 'lib/prettyp/language_detection_service.rb', line 16 def detect_from_input input classified = Linguist::Classifier.classify(Linguist::Samples::DATA, input, possible).first format_language_key(Linguist::Language[classified[0]].name) end |