Class: Rubomop::TodoFile
- Inherits:
-
Object
- Object
- Rubomop::TodoFile
- Defined in:
- lib/rubomop/todo_file.rb
Instance Attribute Summary collapse
-
#cops ⇒ Object
Returns the value of attribute cops.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#header ⇒ Object
Returns the value of attribute header.
-
#raw_lines ⇒ Object
Returns the value of attribute raw_lines.
Instance Method Summary collapse
- #delete!(delete_option) ⇒ Object
- #delete_options(autocorrect_only: true) ⇒ Object
-
#initialize(filename:) ⇒ TodoFile
constructor
A new instance of TodoFile.
- #output ⇒ Object
- #output_lines ⇒ Object
- #parse ⇒ Object
Constructor Details
#initialize(filename:) ⇒ TodoFile
Returns a new instance of TodoFile.
6 7 8 |
# File 'lib/rubomop/todo_file.rb', line 6 def initialize(filename:) @filename = filename end |
Instance Attribute Details
#cops ⇒ Object
Returns the value of attribute cops.
4 5 6 |
# File 'lib/rubomop/todo_file.rb', line 4 def cops @cops end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/rubomop/todo_file.rb', line 3 def filename @filename end |
#header ⇒ Object
Returns the value of attribute header.
4 5 6 |
# File 'lib/rubomop/todo_file.rb', line 4 def header @header end |
#raw_lines ⇒ Object
Returns the value of attribute raw_lines.
4 5 6 |
# File 'lib/rubomop/todo_file.rb', line 4 def raw_lines @raw_lines end |
Instance Method Details
#delete!(delete_option) ⇒ Object
37 38 39 |
# File 'lib/rubomop/todo_file.rb', line 37 def delete!(delete_option) delete_option[:cop].delete!(delete_option[:file]) end |
#delete_options(autocorrect_only: true) ⇒ Object
31 32 33 34 35 |
# File 'lib/rubomop/todo_file.rb', line 31 def (autocorrect_only: true) result = cops.flat_map(&:delete_options) result = result.select { _1[:cop].autocorrect } if autocorrect_only result end |
#output ⇒ Object
27 28 29 |
# File 'lib/rubomop/todo_file.rb', line 27 def output output_lines.join("\n") + "\n" end |
#output_lines ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/rubomop/todo_file.rb', line 17 def output_lines result = header.map(&:chomp) result << "" cops.each do |cop| result += cop.output_lines result << "" end result[0..-2] end |
#parse ⇒ Object
10 11 12 13 14 15 |
# File 'lib/rubomop/todo_file.rb', line 10 def parse self.raw_lines = File.readlines(filename) self.header, *raw_tasks = raw_lines.split("\n") self.cops = raw_tasks.map { Cop.create_and_parse(_1) } self end |