class Handlebars::Helpers::StringFormatting::FormatAs
Format As: Chain a list of string formatters to run sequentially
Public Instance Methods
handlebars_helper()
click to toggle source
# File lib/handlebars/helpers/string_formatting/format_as.rb, line 37 def handlebars_helper proc { |_context, value, formats| wrapper(parse(value, formats)) } end
parse(value, formats)
click to toggle source
Parse will execute a chain of string formatters and run them sequentially
@example
puts FormatAs.new.parse('the quick brown fox', 'pluralize,dashify') the-quick-brown-foxes
@param [String] value - value to format @param [String] formats - comma delimited list of formats @return [String] returns a value that has been processed by multiple formatters
# File lib/handlebars/helpers/string_formatting/format_as.rb, line 25 def parse(value, formats) return '' if value.nil? return value if formats.nil? || formats.empty? formats = formats.split(',') if formats.is_a?(String) formats = formats.map(&:to_sym) formats.each do |format| value = format_value(value, format) end value end
Private Instance Methods
format_value(value, format)
click to toggle source
# File lib/handlebars/helpers/string_formatting/format_as.rb, line 43 def format_value(value, format) return value if format == :none formatter = Handlebars::Helpers.configuration.string_formatter_config[format] unless formatter puts 'Logger not found: format' return value end formatter.parse(value) end