lib/eco/cli/config/help.rb in eco-helpers-2.7.16 vs lib/eco/cli/config/help.rb in eco-helpers-2.7.17

- old
+ new

@@ -1,11 +1,10 @@ module Eco class CLI class Config module Help - - def help(*args) + def help(*_args) raise "this needs to be reimplemented in the child class and return a string" end private @@ -14,15 +13,16 @@ end # Creatas a well aligned line def help_line(key, desc, keys_max_len = key.length, line_len = 100) blanks = keys_max_len + 3 - key.length - blanks = blanks < 0 ? 0 : blanks + blanks = [blanks, 0].max top_line = " #{key}#{" "*blanks} " indent = top_line.length first = true - each_slice_words(desc, line_len - indent).each_with_object([]) do |line, lines| + + each_slice_words(desc, line_len - indent).each_with_object([]) do |line, lines| # rubocop:disable Style/RedundantEach lines << (first ? "#{top_line}#{line}" : "#{" " * indent}#{line}") first = false end.join("\n") end @@ -31,17 +31,19 @@ str.to_s.scan(/[^\s]+|\s+/).each_with_object([]) do |part, out| if "#{liner}#{part}".length <= max_len liner << part else yield(liner) if block_given? - out << liner + + out << liner liner = part.strip end end.tap do |out| - if out.empty? || !liner.empty? - yield(liner) if block_given? - out << liner if liner - end + next unless out.empty? || !liner.empty? + + yield(liner) if block_given? + + out << liner if liner end end end end end