class IceCube::StringBuilder

Attributes

base[W]

Public Class Methods

formatter(type) click to toggle source
# File lib/ice_cube/builders/string_builder.rb, line 30
def self.formatter(type)
  @formatters[type]
end
new() click to toggle source
# File lib/ice_cube/builders/string_builder.rb, line 7
def initialize
  @types = {}
end
register_formatter(type, &formatter) click to toggle source
# File lib/ice_cube/builders/string_builder.rb, line 34
def self.register_formatter(type, &formatter)
  @formatters ||= {}
  @formatters[type] = formatter
end

Public Instance Methods

piece(type, prefix = nil, suffix = nil) click to toggle source
# File lib/ice_cube/builders/string_builder.rb, line 11
def piece(type, prefix = nil, suffix = nil)
  @types[type] ||= []
end
to_s() click to toggle source
# File lib/ice_cube/builders/string_builder.rb, line 15
def to_s
  string = @base || ''
  @types.each do |type, segments|
    if f = self.class.formatter(type)
      current = f.call(segments)
    else
      next if segments.empty?
      current = self.class.sentence(segments)
    end
    f = IceCube::I18n.t('ice_cube.string.format')[type] ? type : 'default'
    string = IceCube::I18n.t("ice_cube.string.format.#{f}", rest: string, current: current)
  end
  string
end