Module: DR::Formatter::Helpers
- Included in:
- DR::Formatter
- Defined in:
- lib/dr/formatter/simple_formatter.rb
Instance Method Summary collapse
- #join(*args, pre: "", post: "", pre_item: "", post_item: "", join: :auto, **_opts) ⇒ Object
- #localize(msg, lang: :en, **_opts) ⇒ Object
- #wrap(content, pre: nil, post: nil) ⇒ Object
Instance Method Details
#join(*args, pre: "", post: "", pre_item: "", post_item: "", join: :auto, **_opts) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# 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) ⇒ Object
18 19 20 21 |
# 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 |