Class: Contextizer::Analyzer
- Inherits:
-
Object
- Object
- Contextizer::Analyzer
- Defined in:
- lib/contextizer/analyzer.rb
Constant Summary collapse
- SPECIALISTS =
Analyzers.constants.map do |const| Analyzers.const_get(const) end.select { |const| const.is_a?(Class) && const < Analyzers::Base }
Class Method Summary collapse
Instance Method Summary collapse
- #analyze ⇒ Object
-
#initialize(target_path:) ⇒ Analyzer
constructor
A new instance of Analyzer.
Constructor Details
#initialize(target_path:) ⇒ Analyzer
Returns a new instance of Analyzer.
13 14 15 |
# File 'lib/contextizer/analyzer.rb', line 13 def initialize(target_path:) @target_path = target_path end |
Class Method Details
.call(target_path:) ⇒ Object
9 10 11 |
# File 'lib/contextizer/analyzer.rb', line 9 def self.call(target_path:) new(target_path: target_path).analyze end |
Instance Method Details
#analyze ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/contextizer/analyzer.rb', line 17 def analyze results = SPECIALISTS.map do |specialist_class| specialist_class.call(target_path: @target_path) end.compact return { language: :unknown, framework: nil, scores: {} } if results.empty? best_result = results.max_by { |result| result[:score] } { language: best_result[:language], framework: best_result[:framework], scores: results.map { |r| [r[:language], r[:score]] }.to_h } end |