Class: ShouldClean::Simulator

Inherits:
Object
  • Object
show all
Defined in:
lib/should_clean/simulator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, buffer = $stdout) ⇒ Simulator

Returns a new instance of Simulator.



8
9
10
11
# File 'lib/should_clean/simulator.rb', line 8

def initialize(file_path, buffer = $stdout)
  @content = File.read(file_path)
  @buffer = buffer
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



6
7
8
# File 'lib/should_clean/simulator.rb', line 6

def buffer
  @buffer
end

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/should_clean/simulator.rb', line 6

def content
  @content
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/should_clean/simulator.rb', line 13

def run
  return unless content.valid_encoding?

  content.each_line.each do |line|
    cleaned = Cleaner.clean(line)
    if cleaned
      buffer.puts("- #{line.strip}")
      buffer.puts("+ #{cleaned.strip}")
    end
  end
end