Class: RubocopChallenger::Rubocop::TodoReader
- Inherits:
-
Object
- Object
- RubocopChallenger::Rubocop::TodoReader
- Defined in:
- lib/rubocop_challenger/rubocop/todo_reader.rb
Overview
To read ‘.rubocop_todo.yml` and parse each rules
Instance Method Summary collapse
-
#all_rules ⇒ Array<Rule>
Array of rubocop rule instances which ordered by offense count.
- #any_rule ⇒ Rule
- #autocorrectable_rules ⇒ Array<Rule>
-
#initialize(rubocop_todo_file_path) ⇒ TodoReader
constructor
A new instance of TodoReader.
- #least_occurrence_rule ⇒ Rule
- #most_occurrence_rule ⇒ Rule
-
#version ⇒ Type
Returns the version of RuboCop used to create the “.rubocop_todo.yml”.
Constructor Details
#initialize(rubocop_todo_file_path) ⇒ TodoReader
Returns a new instance of TodoReader.
7 8 9 |
# File 'lib/rubocop_challenger/rubocop/todo_reader.rb', line 7 def initialize(rubocop_todo_file_path) @rubocop_todo_file_path = rubocop_todo_file_path end |
Instance Method Details
#all_rules ⇒ Array<Rule>
Returns Array of rubocop rule instances which ordered by offense count.
21 22 23 24 25 26 27 28 29 |
# File 'lib/rubocop_challenger/rubocop/todo_reader.rb', line 21 def all_rules @all_rules ||= file_contents .split(/\n{2,}/) .drop(1) # remove header contents .map { |content| Rule.new(content) } .reject { |rule| ignored?(rule) } .sort end |
#any_rule ⇒ Rule
47 48 49 |
# File 'lib/rubocop_challenger/rubocop/todo_reader.rb', line 47 def any_rule autocorrectable_rules.sample end |
#autocorrectable_rules ⇒ Array<Rule>
32 33 34 |
# File 'lib/rubocop_challenger/rubocop/todo_reader.rb', line 32 def autocorrectable_rules all_rules.select(&:autocorrectable?) end |
#least_occurrence_rule ⇒ Rule
37 38 39 |
# File 'lib/rubocop_challenger/rubocop/todo_reader.rb', line 37 def least_occurrence_rule autocorrectable_rules.first end |
#most_occurrence_rule ⇒ Rule
42 43 44 |
# File 'lib/rubocop_challenger/rubocop/todo_reader.rb', line 42 def most_occurrence_rule autocorrectable_rules.last end |
#version ⇒ Type
Returns the version of RuboCop used to create the “.rubocop_todo.yml”
14 15 16 17 |
# File 'lib/rubocop_challenger/rubocop/todo_reader.rb', line 14 def version file_contents =~ /using RuboCop version (\d{1,}\.\d{1,}\.\d{1,})/ Regexp.last_match(1) end |