module DR::Formatter::Helpers

Public Instance Methods

join(*args, pre: "", post: "", pre_item: "", post_item: "", join: :auto, **_opts) click to toggle source
# File lib/dr/formatter/simple_formatter.rb, line 23
def join(*args, pre: "", post: "", pre_item: "", post_item: "", join: :auto, **_opts)
        args=Array(args)
        list=args.compact.map {|i| wrap(i, pre: pre_item, post: post_item)}.delete_if {|i| i.empty?}
        r=list.shift
        list.each do |s|
                if join==:auto
                        if r[-1]=="\n" or s[1]=="\n"
                                r+=s
                        else
                                r+=" "+s
                        end
                else
                        r+=join+s
                end
        end
        r=pre+r+post unless r.nil? or r.empty?
        r
end
localize(msg, lang: :en, **_opts) { |msg| ... } click to toggle source
# File lib/dr/formatter/simple_formatter.rb, line 4
def localize(msg, lang: :en, **_opts)
        case msg
        when Hash
                Array(lang).each do |l|
                        if msg.key?(l)
                                yield(msg[l]) if block_given?
                                return msg[l]
                        end
                end
        else
                msg
        end
end
wrap(content, pre:nil, post:nil) click to toggle source
# File lib/dr/formatter/simple_formatter.rb, line 18
def wrap(content, pre:nil, post:nil)
        return content if content.nil? or content.empty?
        pre.to_s+content.to_s+post.to_s
end