Class: PdfTemplator::Formatter

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

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Formatter

Returns a new instance of Formatter.



7
8
9
# File 'lib/pdf_templator/formatter.rb', line 7

def initialize(content)
  @content = content
end

Instance Method Details

#apply(type, args = {}) ⇒ string

Format content

Parameters:

  • type (string)

    money | number | date | string

  • args (hash) (defaults to: {})

    :locale, :format

Returns:

  • (string)


16
17
18
19
20
21
22
# File 'lib/pdf_templator/formatter.rb', line 16

def apply(type, args = {})
  # Symbolize keys
  args = args.map { |k, v| [k.to_sym, v] }.to_h
  I18n.locale = args[:locale] || :en
  klass = PdfTemplator.string_to_type_class(type)
  klass.new(@content, args).call
end