class Handlebars::Helpers::StringFormatting::Padr

Add padding to the right of the value.

Public Instance Methods

handlebars_helper() click to toggle source
# File lib/handlebars/helpers/string_formatting/padr.rb, line 47
def handlebars_helper
  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) click to toggle source

Parse will Add padding to the right of the value.

@example

puts "[#{Padr.new.parse('aaa', 10)}]"

[aaa       ]

@example

puts "[#{Padr.new.parse('aaa')}]"

[aaa                           ]

@example

puts Padr.new.parse('aaa', '10', '-')

aaa-------

@param [String] value - value to apply padding to @param [Integer] count - how much padding to apply. defaults to configuration.padr_count @param [String] char - character to pad with. defaults to configuration.padr_char @return [String] value with padding to right

# File lib/handlebars/helpers/string_formatting/padr.rb, line 39
def parse(value, count = nil, char = nil)
  value = '' if value.nil?
  count = Handlebars::Helpers.configuration.padr_count if count.nil?
  count = count.to_i if count.is_a?(String)
  char = Handlebars::Helpers.configuration.padr_char if char.nil?
  value.to_s.ljust(count, char)
end