Class: Handlebars::Helpers::StringFormatting::FormatAs
- Inherits:
-
BaseHelper
- Object
- BaseHelper
- Handlebars::Helpers::StringFormatting::FormatAs
- Defined in:
- lib/handlebars/helpers/string_formatting/format_as.rb
Overview
Format As: Chain a list of string formatters to run sequentially
Instance Method Summary collapse
- #handlebars_helper ⇒ Object
-
#parse(value, formats) ⇒ String
Parse will execute a chain of string formatters and run them sequentially.
Methods inherited from BaseHelper
#parse_json, #struct_to_hash, #tokenizer, #wrapper
Instance Method Details
#handlebars_helper ⇒ Object
37 38 39 |
# File 'lib/handlebars/helpers/string_formatting/format_as.rb', line 37 def proc { |_context, value, formats| wrapper(parse(value, formats)) } end |
#parse(value, formats) ⇒ String
Parse will execute a chain of string formatters and run them sequentially
25 26 27 28 29 30 31 32 33 34 35 |
# 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 |