lib/glyptodont/checkers/age.rb in glyptodont-0.1.0 vs lib/glyptodont/checkers/age.rb in glyptodont-0.2.0
- old
+ new
@@ -8,35 +8,43 @@
@todos = todos
@threshold = threshold
end
def check
- @age, @reportable_todos = oldest_todos
message
end
def passed?
- todos.empty? || age <= threshold
+ stale_todos.empty?
end
private
- attr_reader :todos, :threshold, :age, :reportable_todos
+ attr_reader :todos, :threshold
def message
if todos.empty?
"Nothing left to do"
elsif passed?
- "At #{Glyptodont.pluralize(age, "day")}, TODOs are fresh enough for now"
+ "At #{Glyptodont.pluralize(oldest_age, "day")}, TODOs are fresh enough for now"
else
- "Some TODOs are too stale at #{Glyptodont.pluralize(age, "day")} old:\n" +
- reportable_todos.map { |t| Glyptodont.format_todo(t) }.join("\n")
+ "Some TODOs are too stale at more than #{Glyptodont.pluralize(youngest_stale - 1, "day")} old:\n" +
+ stale_todos.map { |t| Glyptodont.format_todo(t) }.join("\n")
end
end
- def oldest_todos
- todos.group_by { |todo| todo[:age] }
- .max_by { |age, _group| age }
+ def stale_todos
+ @stale_todos ||= todos.select { |todo| todo[:age] > threshold }
+ .sort_by { |todo| todo[:age] }
+ .reverse
+ end
+
+ def oldest_age
+ todos.max_by { |t| t[:age] }[:age]
+ end
+
+ def youngest_stale
+ stale_todos.last[:age]
end
end
end
end