class IceCube::StringBuilder
Attributes
Public Class Methods
Source
# File lib/ice_cube/builders/string_builder.rb, line 28 def self.formatter(type) @formatters[type] end
Source
# File lib/ice_cube/builders/string_builder.rb, line 32 def self.register_formatter(type, &formatter) @formatters ||= {} @formatters[type] = formatter end
Public Instance Methods
Source
# File lib/ice_cube/builders/string_builder.rb, line 9 def piece(type, prefix = nil, suffix = nil) @types[type] ||= [] end
Source
# File lib/ice_cube/builders/string_builder.rb, line 13 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