Class: Filigree::Configuration::Option
- Defined in:
- lib/filigree/configuration.rb
Overview
This class represents an option that can appear in the configuration.
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#handler ⇒ Object
Returns the value of attribute handler.
-
#help ⇒ Object
Returns the value of attribute help.
-
#long ⇒ Object
Returns the value of attribute long.
-
#short ⇒ Object
Returns the value of attribute short.
Class Method Summary collapse
-
.to_s(options, indent = 0) ⇒ String
Helper method used to print out information on a set of options.
Instance Method Summary collapse
-
#arity ⇒ Fixnum
Returns the number of arguments that this option takes.
-
#to_s(max_long, max_short, indent = 0) ⇒ String
Print the option information out as a string.
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default
341 342 343 |
# File 'lib/filigree/configuration.rb', line 341 def default @default end |
#handler ⇒ Object
Returns the value of attribute handler
341 342 343 |
# File 'lib/filigree/configuration.rb', line 341 def handler @handler end |
#help ⇒ Object
Returns the value of attribute help
341 342 343 |
# File 'lib/filigree/configuration.rb', line 341 def help @help end |
#long ⇒ Object
Returns the value of attribute long
341 342 343 |
# File 'lib/filigree/configuration.rb', line 341 def long @long end |
#short ⇒ Object
Returns the value of attribute 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.
381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/filigree/configuration.rb', line 381 def self.to_s(, indent = 0) lines = [] max_long = .lazy.map { |opt| opt.long.length }.max max_short = .lazy.map(&:short).reject { |opt| opt.nil? }.map(&:length).max .each do |opt| lines << opt.to_s(max_long, max_short, indent) end lines.join("\n") end |
Instance Method Details
#arity ⇒ Fixnum
Returns the number of arguments that this 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
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 |