class Nucop::Helpers::NextCopForPromotion

Constants

Todo

Public Class Methods

new(todo_filepath) click to toggle source
# File lib/nucop/helpers/next_cop_for_promotion.rb, line 6
def initialize(todo_filepath)
  @todo_filepath = todo_filepath
  extract_todos
  sort_todos_by_offense_count
end

Public Instance Methods

find(how_many = 5) click to toggle source
# File lib/nucop/helpers/next_cop_for_promotion.rb, line 12
def find(how_many = 5)
  @todos.take(how_many)
end

Private Instance Methods

each_line() { |line| ... } click to toggle source
# File lib/nucop/helpers/next_cop_for_promotion.rb, line 41
def each_line
  File.open(@todo_filepath, "r") do |file|
    file.each_line do |line|
      yield line
    end
  end
end
extract_offense_counts_and_names() click to toggle source
# File lib/nucop/helpers/next_cop_for_promotion.rb, line 25
def extract_offense_counts_and_names
  data = []

  each_line do |line|
    if (count_match = line.match(/Offense count: (\d+)/))
      data << count_match.captures.first
    end

    if (name_match = line.match(/^(\w+\/\w+):$/))
      data << name_match.captures.first
    end
  end

  data
end
extract_todos() click to toggle source
# File lib/nucop/helpers/next_cop_for_promotion.rb, line 18
def extract_todos
  @todos =
    extract_offense_counts_and_names
      .each_slice(2)
      .map { |count, name| Todo.new(name, count.to_i) }
end
sort_todos_by_offense_count() click to toggle source
# File lib/nucop/helpers/next_cop_for_promotion.rb, line 49
def sort_todos_by_offense_count
  @todos.sort! { |i, j| i.offenses <=> j.offenses }
end