Class: Linter::BaseAssociation
- Inherits:
-
Object
- Object
- Linter::BaseAssociation
show all
- Defined in:
- lib/linter/base_association.rb
Constant Summary
collapse
- SKIP_WORDS =
%w[directory director].freeze
Class Method Summary
collapse
Class Method Details
.add_recommendation(_result) ⇒ Object
47
48
49
|
# File 'lib/linter/base_association.rb', line 47
def self.add_recommendation(_result)
false
end
|
.analyze(text) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/linter/base_association.rb', line 7
def self.analyze(text)
result = OpenStruct.new(trend: '')
wordlists.dig('words').each do |key, words|
word_count_key = "#{key}_word_counts".to_sym
result[word_count_key] = {}
words.each do |word|
result.send(word_count_key).merge!(word_count(text, word))
end
end
result.trend = calculate_trend(result)
result.recommendation = add_recommendation(result)
result
end
|
.recommendation_file ⇒ Object
42
43
44
45
|
# File 'lib/linter/base_association.rb', line 42
def self.recommendation_file
file_path = File.join(__dir__, '../../data/recommendations.yml')
@recommendation_file ||= YAML.load_file(file_path)
end
|
.word_count(text, word) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/linter/base_association.rb', line 23
def self.word_count(text, word)
if self::FULL_WORD
regex = /\b#{word}\b/i
else
regex = /\b(#{word}\w*)\b/i
end
matches = text.scan(regex)
return {} unless matches.any?
matches
.flatten
.map(&:downcase)
.reject { |m| SKIP_WORDS.include? m}
.group_by { |v| v }
.transform_values(&:size)
.to_h
end
|