Class: Logger
- Inherits:
-
Object
- Object
- Logger
- Defined in:
- lib/logger.rb
Overview
The Logger class provides utility methods for printing console logs with different formatting.
Class Method Summary collapse
-
.duplicate(string, duplicate) ⇒ Object
Prints a string and its duplicate.
-
.error(message) ⇒ Object
Prints an error message.
-
.file_not_found(file) ⇒ Object
Prints a file not found error message.
-
.header(text) ⇒ Object
Prints a header.
-
.key_transform(old_key, string) ⇒ Object
Prints a key transfom message.
-
.lost_keys(keys) ⇒ Object
Prints the lost keys.
- .oversize(original, string) ⇒ Object
-
.string(string) ⇒ Object
Prints a string value.
-
.string_value(key, value) ⇒ Object
Prints a string value.
Class Method Details
.duplicate(string, duplicate) ⇒ Object
Prints a string and its duplicate.
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.
73 74 75 |
# File 'lib/logger.rb', line 73 def self.error() puts Paint["Error: #{message}", :red] end |
.file_not_found(file) ⇒ Object
Prints a file not found error message.
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.
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.
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.
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.
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.
18 19 20 |
# File 'lib/logger.rb', line 18 def self.string_value(key, value) puts Formatter.string(key, value) end |