Class: Yalphabetize::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/yalphabetize/logger.rb

Constant Summary collapse

DEFAULT_OUTPUT =
$stdout

Instance Method Summary collapse

Constructor Details

#initialize(output = DEFAULT_OUTPUT) ⇒ Logger

Returns a new instance of Logger.



7
8
9
10
11
# File 'lib/yalphabetize/logger.rb', line 7

def initialize(output = DEFAULT_OUTPUT)
  @output = output
  @inspected_count = 0
  @offences = {}
end

Instance Method Details

#final_summaryObject



28
29
30
31
32
33
# File 'lib/yalphabetize/logger.rb', line 28

def final_summary
  output.puts "\nInspected: #{inspected_count}"
  output.puts send(list_offences_color, "Offences: #{offences.size}")

  offences.each { |file_path, status| puts_offence(file_path, status) }
end

#initial_summary(file_paths) ⇒ Object



13
14
15
# File 'lib/yalphabetize/logger.rb', line 13

def initial_summary(file_paths)
  output.puts "Inspecting #{file_paths.size} YAML files"
end

#log_correction(file_path) ⇒ Object



39
40
41
# File 'lib/yalphabetize/logger.rb', line 39

def log_correction(file_path)
  offences[file_path] = :corrected
end

#log_no_offenceObject



23
24
25
26
# File 'lib/yalphabetize/logger.rb', line 23

def log_no_offence
  @inspected_count += 1
  output.print green '.'
end

#log_offence(file_path) ⇒ Object



17
18
19
20
21
# File 'lib/yalphabetize/logger.rb', line 17

def log_offence(file_path)
  @inspected_count += 1
  offences[file_path] = :detected
  output.print red 'O'
end

#offences?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/yalphabetize/logger.rb', line 35

def offences?
  @offences.any?
end