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.



73
74
75
# File 'lib/logger.rb', line 73

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.



56
57
58
# File 'lib/logger.rb', line 56

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.



47
48
49
50
51
# File 'lib/logger.rb', line 47

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.



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

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.



63
64
65
66
67
68
# File 'lib/logger.rb', line 63

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

.oversize(original, string) ⇒ Object



30
31
32
33
34
# File 'lib/logger.rb', line 30

def self.oversize(original, string)
  length = original.value.length
  puts "#{Formatter.string(original.key,
                           original.value)} ↔ #{Paint[string[0...length], :blue]}#{Paint[string[length...], :red]}"
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