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
- #active_cops ⇒ Object
- #cop_for(name) ⇒ Object
-
#initialize(filename:) ⇒ TodoFile
constructor
A new instance of TodoFile.
- #output ⇒ Object
- #output_lines ⇒ Object
- #parse ⇒ Object
- #save! ⇒ 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
#active_cops ⇒ Object
21 22 23 |
# File 'lib/rubomop/todo_file.rb', line 21 def active_cops cops.select { _1.active? } end |
#cop_for(name) ⇒ Object
17 18 19 |
# File 'lib/rubomop/todo_file.rb', line 17 def cop_for(name) cops.select { _1.name == name }.first end |
#output ⇒ Object
35 36 37 |
# File 'lib/rubomop/todo_file.rb', line 35 def output output_lines.join("\n") + "\n" end |
#output_lines ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/rubomop/todo_file.rb', line 25 def output_lines result = header.map(&:chomp) result << "" active_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 |
#save! ⇒ Object
39 40 41 42 |
# File 'lib/rubomop/todo_file.rb', line 39 def save! FileUtils.rm_f(filename) File.write(filename, output || "") end |