class MOTD

Attributes

components[R]
config[R]

Public Class Methods

new(config_path = nil, process = true) click to toggle source

Creates an MOTD by parsing the provided config file, and processing each component.

@param config_path [String] The path to the configuration file. If not

provided, the default config path will be used.

@param process [Boolean] whether or not to actually process and evaluate

the printable results of each component
# File lib/panda_motd/motd.rb, line 15
def initialize(config_path = nil, process = true)
  @config = Config.new(config_path)
  @components = @config.components_enabled.map { |ce| ce.new(self) }
  @components.each(&:process) if process
end

Public Instance Methods

to_s() click to toggle source

Takes each component on the MOTD and joins them together in a printable format. It inserts two newlines in between each component, ensuring that there is one empty line between each. If a component has any errors, the error will be printed in a clean way.

# File lib/panda_motd/motd.rb, line 25
def to_s
  @components.map do |c|
    if c.errors.any?
      c.errors.map(&:to_s).join("\n")
    else
      c.to_s
    end
  end.join("\n\n")
end