Class: Filigree::Configuration::Option

Inherits:
Struct
  • Object
show all
Defined in:
lib/filigree/configuration.rb

Overview

This class represents an option that can appear in the configuration.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultObject

Returns the value of attribute default

Returns:

  • (Object)

    the current value of default



341
342
343
# File 'lib/filigree/configuration.rb', line 341

def default
  @default
end

#handlerObject

Returns the value of attribute handler

Returns:

  • (Object)

    the current value of handler



341
342
343
# File 'lib/filigree/configuration.rb', line 341

def handler
  @handler
end

#helpObject

Returns the value of attribute help

Returns:

  • (Object)

    the current value of help



341
342
343
# File 'lib/filigree/configuration.rb', line 341

def help
  @help
end

#longObject

Returns the value of attribute long

Returns:

  • (Object)

    the current value of long



341
342
343
# File 'lib/filigree/configuration.rb', line 341

def long
  @long
end

#shortObject

Returns the value of attribute short

Returns:

  • (Object)

    the current value of short



341
342
343
# File 'lib/filigree/configuration.rb', line 341

def short
  @short
end

Class Method Details

.to_s(options, indent = 0) ⇒ String

Helper method used to print out information on a set of options.

Parameters:

  • options (Array<Option>)

    Options to be printed

  • indent (Fixnum) (defaults to: 0)

    Indentation to be placed before each line

Returns:



381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/filigree/configuration.rb', line 381

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

Instance Method Details

#arityFixnum

Returns the number of arguments that this option takes.

Returns:

  • (Fixnum)

    Number of arguments the option takes



345
346
347
348
349
350
# File 'lib/filigree/configuration.rb', line 345

def arity
	case self.handler
	when Array then self.handler.length
	when Proc  then self.handler.arity
	end
end

#to_s(max_long, max_short, indent = 0) ⇒ String

Print the option information out as a string.

Layout: | ||–‘long`,|| ||-`short`|| - | |_||_||_||__||_|

indent    max_l+3  1   max_s+1   3

Parameters:

  • max_long (Fixnum)

    Maximim length of all long argumetns being printed in a block

  • max_short (Fixnum)

    Maximum length of all short arguments being printed in a block

  • indent (Fixnum) (defaults to: 0)

    Indentation to be placed before each line

Returns:



364
365
366
367
368
369
370
371
372
373
# File 'lib/filigree/configuration.rb', line 364

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