Method: Handlebars::Helpers::StringFormatting::AppendIf#parse

Defined in:
lib/handlebars/helpers/string_formatting/append_if.rb

#parse(value, suffix, formats) ⇒ String

Parse will Append If will append suffix to value, if value is not empty

Examples:


puts AppendIf.new.parse('the quick brown', 'fox', 'dashify')

the-quick-brown-fox

Parameters:

  • value (String)
    • value to add suffix too

  • suffix (String)
    • suffix to add to value

  • formats (String)
    • list of formats to apply to value, defaults to none

Returns:

  • (String)

    value + suffix when value exists, otherwise ”



27
28
29
30
# File 'lib/handlebars/helpers/string_formatting/append_if.rb', line 27

def parse(value, suffix, formats)
  format_as = Handlebars::Helpers::StringFormatting::FormatAs.new
  value.present? ? "#{format_as.parse(value, formats)}#{suffix}" : ''
end