Module: ChiliPDF::TokenManager

Extended by:
TokenManager
Included in:
TokenManager
Defined in:
lib/chili_pdf/token_manager.rb

Constant Summary collapse

MAPPINGS =
{:current_page => {
:replacement_object  => "[page]",
:description         => "The current page of the PDF document."},
                :total_pages => {
:replacement_object  => '[topage]',
:description         => "The total number of pages in the PDF document."},
                :datestamp => {
:replacement_object  => lambda {Time.now.strftime('%d-%b-%Y')},
:description         => "The current date in the format of DD-MON-YYYY'"},
                :current_quarter => {
:replacement_object => lambda {calculate_quarter.to_s},
:description        => "The current fiscal quarter (assuming Jan-Mar is thefirst quarter). Example output: '1'."},
                :current_year => {
:replacement_object => lambda {Time.now.strftime('%Y')},
:description        => "The current year in YYYY-format"}}

Instance Method Summary collapse

Instance Method Details

#add_token_definitionObject



27
28
29
# File 'lib/chili_pdf/token_manager.rb', line 27

def add_token_definition
  raw_tokens.merge!(yield)
end

#apply_tokens_to(string) ⇒ Object



31
32
33
# File 'lib/chili_pdf/token_manager.rb', line 31

def apply_tokens_to(string)
  tokens.inject(string.dup) {|modified, token| modified = token.apply_to modified}
end

#tokensObject



21
22
23
24
25
# File 'lib/chili_pdf/token_manager.rb', line 21

def tokens
  raw_tokens.map {|matcher, meta|
    StringToken.new(matcher, meta[:replacement_object], meta[:description])
  }
end