module Pronto::Formatter

Public Class Methods

get(names) click to toggle source
# File lib/pronto/formatter/formatter.rb, line 16
def get(names)
  names ||= 'text'
  Array(names).map { |name| @formatters[name.to_s] || TextFormatter }
    .uniq.map(&:new)
end
names() click to toggle source
# File lib/pronto/formatter/formatter.rb, line 22
def names
  @formatters.keys
end
register(formatter_klass) click to toggle source
# File lib/pronto/formatter/formatter.rb, line 4
def register(formatter_klass)
  unless formatter_klass.method_defined?(:format)
    raise NoMethodError, "format method is not declared in the #{formatter_klass.name} class."
  end

  base = Pronto::Formatter::Base
  raise "#{formatter_klass.name} is not a #{base}" unless formatter_klass.ancestors.include?(base)

  @formatters ||= {}
  @formatters[formatter_klass.name] = formatter_klass
end