lib/inch/api/suggest.rb in inch-0.4.10 vs lib/inch/api/suggest.rb in inch-0.5.0.rc1
- old
+ new
@@ -1,13 +1,13 @@
-require "inch/utils/weighted_list"
+require 'inch/utils/weighted_list'
module Inch
module API
class Suggest < Filter
def initialize(codebase, options)
super
- @options = Options::Suggest.new(options)
+ @options = Options::Suggest(options)
end
def files
list = files_sorted_by_importance
how_many = @options.file_count || list.size
@@ -17,10 +17,11 @@
# @return [Array] the +@options.object_count+ objects the API suggests
def objects
filter_objects_to_display
end
+
# @return [Array] all the objects that match +@options+
def all_objects
relevant_objects
end
@@ -49,26 +50,27 @@
weighted_list = Utils::WeightedList.new(graded_list, object_list_counts)
list = Codebase::Objects.sort_by_priority(weighted_list.to_a.flatten)
- list = list[0...object_count] if list.size > object_count
+ if list.size > object_count
+ list = list[0...object_count]
+ end
list
end
def files_sorted_by_importance
list = all_filenames(relevant_objects).uniq.map do |filename|
- Evaluation::File.for(filename, relevant_objects)
+ 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
- Codebase::Objects.sort_by_priority(
- priority_list.empty? ? list : priority_list)
+ Codebase::Objects.sort_by_priority(priority_list.empty? ? list : priority_list)
end
def all_filenames(objects)
codebase.objects.map do |o|
o.files.map(&:filename)
@@ -83,11 +85,11 @@
def grades
codebase.objects.map(&:grade).uniq
end
def grade_list(grade_symbol)
- grade_lists.find { |r| r.grade.to_sym == grade_symbol }
+ grade_lists.detect { |r| r.grade.to_sym == grade_symbol }
end
def select_by_priority(list, min_priority)
list.select { |o| o.priority >= min_priority }
end
@@ -95,11 +97,10 @@
def relevant_grades
grades.size >= 2 ? grades[-2..-1] : [grades.last].compact
end
def relevant_objects
- @relevant_objects ||= select_by_priority(codebase.objects,
- @options.object_min_priority)
+ @relevant_objects ||= select_by_priority(codebase.objects, @options.object_min_priority)
end
def relevant_priorities
(@options.object_min_priority..99)
end