Class: Logger

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

Overview

The Logger class provides utility methods for printing console logs with different formatting.

Class Method Summary collapse

Class Method Details

.duplicate(string, duplicate) ⇒ Object

Prints a string and its duplicate.

Parameters:

  • string (LocoString)

    The original string.

  • duplicate (LocoString)

    The duplicate string.



26
27
28
# File 'lib/logger.rb', line 26

def self.duplicate(string, duplicate)
  puts "#{Formatter.string(string.key, string.value)}#{Paint[duplicate.value.to_s, :blue]}"
end

.error(message) ⇒ Object

Prints an error message.

Parameters:

  • message (String)

    The error message to print.



67
68
69
# File 'lib/logger.rb', line 67

def self.error(message)
  puts Paint["Error: #{message}", :red]
end

.file_not_found(file) ⇒ Object

Prints a file not found error message.

Parameters:

  • file (String)

    The file that was not found.



50
51
52
# File 'lib/logger.rb', line 50

def self.file_not_found(file)
  puts Paint["#{file} not found", :red]
end

.header(text) ⇒ Object

Prints a header.

Parameters:

  • text (String)

    The text to print as the header.



41
42
43
44
45
# File 'lib/logger.rb', line 41

def self.header(text)
  puts "=" * text.length
  puts text
  puts "=" * text.length
end

.key_transform(old_key, string) ⇒ Object

Prints a key transfom message.

Parameters:

  • old_key (String)

    The old key.

  • string (LocoString)

    The LocoString object with a new key.



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

def self.key_transform(old_key, string)
  puts "#{Paint[old_key, :red]}#{Formatter.string(string.key, string.value)}"
end

.lost_keys(keys) ⇒ Object

Prints the lost keys.

Parameters:

  • keys (Array<String>)

    The lost keys to print.



57
58
59
60
61
62
# File 'lib/logger.rb', line 57

def self.lost_keys(keys)
  return if keys.empty?

  puts "Lost keys: #{keys.length}"
  puts keys.map { |key| Paint[key.to_s, :red] }.join(", ")
end

.string(string) ⇒ Object

Prints a string value.

Parameters:

  • string (LocoString)

    The LocoString object to print.



10
11
12
# File 'lib/logger.rb', line 10

def self.string(string)
  puts Formatter.string(string.key, string.value)
end

.string_value(key, value) ⇒ Object

Prints a string value.

Parameters:

  • key (String)

    The key of the string.

  • value (String)

    The value of the string.



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

def self.string_value(key, value)
  puts Formatter.string(key, value)
end