class Filigree::Configuration::Option
This class represents an option that can appear in the configuration.
Public Class Methods
Helper method used to print out information on a set of options.
@param [Array<Option>] options Options to be printed @param [Fixnum] indent Indentation to be placed before each line
@return [String]
# File lib/filigree/configuration.rb, line 398 def self.to_s(options, indent = 0) lines = [] max_long = options.lazy.map { |opt| opt.long.length }.max max_short = options.lazy.map(&:short).reject { |opt| opt.nil? }.map(&:length).max options.each do |opt| lines << opt.to_s(max_long, max_short, indent) end lines.join("\n") end
Public Instance Methods
Returns the number of arguments that this option takes.
@return [Fixnum] Number of arguments the option takes
# File lib/filigree/configuration.rb, line 362 def arity case self.handler when Array then self.handler.length when Proc then self.handler.arity end end
Print the option information out as a string.
Layout: | ||–`long`,|| ||-`short`|| | |_||_||_||__||_|
indent max_l+3 1 max_s+1 3
@param [Fixnum] max_long Maximim length of all long argumetns being printed in a block @param [Fixnum] max_short Maximum length of all short arguments being printed in a block @param [Fixnum] indent Indentation to be placed before each line
@return [String]
# File lib/filigree/configuration.rb, line 381 def to_s(max_long, max_short, indent = 0) segment_indent = indent + max_long + max_short + 8 segmented_help = self.help.segment(segment_indent) if self.short sprintf "#{' ' * indent}%-#{max_long + 3}s %-#{max_short + 1}s %s", "--#{self.long},", '-' + self.short, segmented_help else sprintf "#{' ' * indent}%-#{max_long + max_short + 5}s %s", '--' + self.long, segmented_help end end