Class: Inch::CLI::Command::Suggest
- Inherits:
-
List
show all
- Defined in:
- lib/inch/cli/command/suggest.rb
Instance Attribute Summary
Attributes inherited from Base
#source_parser
Instance Method Summary
collapse
Methods inherited from BaseList
#initialize, #prepare_list
Methods inherited from Base
#initialize, #name, run
#debug, #trace, #trace_header
Instance Method Details
#all_filenames(objects) ⇒ Object
66
67
68
69
70
|
# File 'lib/inch/cli/command/suggest.rb', line 66
def all_filenames(objects)
objects.map do |o|
o.files.map(&:first)
end.flatten
end
|
#description ⇒ Object
5
6
7
|
# File 'lib/inch/cli/command/suggest.rb', line 5
def description
'Suggests some objects to be doucmented (better)'
end
|
#files ⇒ Object
47
48
49
50
51
|
# File 'lib/inch/cli/command/suggest.rb', line 47
def files
list = files_sorted_by_importance
how_many = @options.file_count || list.size
list[0...how_many]
end
|
#files_sorted_by_importance ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/inch/cli/command/suggest.rb', line 53
def files_sorted_by_importance
list = all_filenames(relevant_objects).uniq.map do |filename|
f = Evaluation::File.for(filename, relevant_objects)
end
priority_list = list.select do |f|
relevant_grades.include?(f.grade) &&
relevant_priorities.include?(f.priority)
end
sort_by_priority(priority_list.empty? ? list : priority_list)
end
|
#filter_objects_to_display ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/inch/cli/command/suggest.rb', line 27
def filter_objects_to_display
list = []
@options.grades_to_display.map do |grade|
r = range(grade)
arr = select_by_priority(r.objects, @options.object_min_priority)
arr = arr.select { |o| o.score <= @options.object_max_score }
list.concat arr
end
list = sort_by_priority(list)
if list.size > @options.object_count
list = list[0...@options.object_count]
elsif list.size < @options.object_count
end
list
end
|
#grades ⇒ Array<Symbol>
Returns the unique grades assigned to objects
grades
77
78
79
|
# File 'lib/inch/cli/command/suggest.rb', line 77
def grades
objects.map(&:grade).uniq
end
|
#objects_to_display ⇒ Object
23
24
25
|
# File 'lib/inch/cli/command/suggest.rb', line 23
def objects_to_display
@objects_to_display ||= filter_objects_to_display
end
|
#range(grade) ⇒ Object
81
82
83
|
# File 'lib/inch/cli/command/suggest.rb', line 81
def range(grade)
@ranges.detect { |r| r.grade == grade }
end
|
#relevant_grades ⇒ Object
89
90
91
|
# File 'lib/inch/cli/command/suggest.rb', line 89
def relevant_grades
grades.size >= 2 ? grades[-2..-1] : [grades.last].compact
end
|
#relevant_objects ⇒ Object
85
86
87
|
# File 'lib/inch/cli/command/suggest.rb', line 85
def relevant_objects
select_by_priority(objects, @options.object_min_priority)
end
|
#relevant_priorities ⇒ Object
93
94
95
|
# File 'lib/inch/cli/command/suggest.rb', line 93
def relevant_priorities
(@options.object_min_priority..99)
end
|
#run(*args) ⇒ void
This method returns an undefined value.
Runs the commandline utility, parsing arguments and displaying a list of objects
18
19
20
21
|
# File 'lib/inch/cli/command/suggest.rb', line 18
def run(*args)
prepare_list(*args)
Output::Suggest.new(@options, objects_to_display, relevant_objects, @ranges, files)
end
|
#select_by_priority(list, min_priority) ⇒ Object
97
98
99
|
# File 'lib/inch/cli/command/suggest.rb', line 97
def select_by_priority(list, min_priority)
list.select { |o| o.priority >= min_priority }
end
|
#usage ⇒ Object
9
10
11
|
# File 'lib/inch/cli/command/suggest.rb', line 9
def usage
'Usage: inch suggest [paths] [options]'
end
|