Class: Fuelcell::Help::DescFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/fuelcell/help/desc_formatter.rb

Constant Summary

Constants inherited from BaseFormatter

BaseFormatter::DEFAULT_PADDING, BaseFormatter::DEFAULT_WIDTH

Instance Attribute Summary

Attributes inherited from BaseFormatter

#max_width, #padding, #width

Instance Method Summary collapse

Methods inherited from BaseFormatter

#initialize, #long_opt, #short_opt

Constructor Details

This class inherits a constructor from Fuelcell::Help::BaseFormatter

Instance Method Details

#call(data) ⇒ Object



5
6
7
8
# File 'lib/fuelcell/help/desc_formatter.rb', line 5

def call(data)
  return '' if empty?(data)
  wrap(data[:long_desc] || data[:desc]) + "\n"
end

#empty?(data) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/fuelcell/help/desc_formatter.rb', line 15

def empty?(data)
  (!data.key?(:desc) || data[:desc].to_s.empty?) &&
    (!data.key?(:long_desc) || data[:long_desc].to_s.empty?)
end

#wrap(text) ⇒ Object



10
11
12
13
# File 'lib/fuelcell/help/desc_formatter.rb', line 10

def wrap(text)
  pattern = /(.{1,#{max_width}})(\s+|$)/
  text.gsub(pattern, "\\1\n").strip
end