Class: Worklog::LogEntryFormatters::BaseFormatter

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

Overview

The base formatter provides common functionality and prints the message including the metadata (ticket, tags, url, project) in a formatted way. It also replaces people handles with their names if known.

Direct Known Subclasses

ConsoleFormatter, SimpleFormatter

Instance Method Summary collapse

Constructor Details

#initialize(known_people = nil) ⇒ BaseFormatter

Constructor

Parameters:

  • known_people (Hash<String, Person>) (defaults to: nil)

    A hash of people with their handles as keys.



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

def initialize(known_people = nil)
  @known_people = known_people
end

Instance Method Details

#format(log_entry) ⇒ String

Format the log entry message with metadata.

Parameters:

  • log_entry (LogEntry)

    the log entry to format.

Returns:

  • (String)

    the formatted message.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/log_entry_formatters.rb', line 20

def format(log_entry)
  # replace all mentions of people with their names.
  msg = log_entry.message.dup
  s = String.new
  s << source_prefix(log_entry)
  s << epic_prefix if log_entry.epic
  s << replace_people_handles(log_entry, msg)
  # Add a space between the message and the metadata if there is any metadata to add.
  s << ' ' unless (log_entry).empty?
  s << (log_entry)
  s
end