Class: Handlebars::Helpers::StringFormatting::Padr
- Inherits:
-
BaseSafeStringHelper
- Object
- BaseHelper
- BaseSafeStringHelper
- Handlebars::Helpers::StringFormatting::Padr
- Defined in:
- lib/handlebars/helpers/string_formatting/padr.rb
Overview
Add padding to the right of the value.
Instance Method Summary collapse
- #handlebars_helper ⇒ Object
-
#parse(value, count = nil, char = nil) ⇒ String
Parse will Add padding to the right of the value.
Methods inherited from BaseSafeStringHelper
Methods inherited from BaseHelper
#parse_json, #struct_to_hash, #tokenizer, #wrapper
Instance Method Details
#handlebars_helper ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/handlebars/helpers/string_formatting/padr.rb', line 47 def proc do |_context, value, count, char| # Handle optional: value, count and char value = nil if value.is_a?(V8::Object) count = nil if count.is_a?(V8::Object) char = nil if char.is_a?(V8::Object) wrapper(parse(value, count, char)) end end |
#parse(value, count = nil, char = nil) ⇒ String
Parse will Add padding to the right of the value.
39 40 41 42 43 44 45 |
# File 'lib/handlebars/helpers/string_formatting/padr.rb', line 39 def parse(value, count = nil, char = nil) value = '' if value.nil? count = ::Helpers.configuration.padr_count if count.nil? count = count.to_i if count.is_a?(String) char = ::Helpers.configuration.padr_char if char.nil? value.to_s.ljust(count, char) end |