Class: Cri::OptionDefinition
- Inherits:
- 
      Object
      
        - Object
- Cri::OptionDefinition
 
- Defined in:
- lib/cri/option_definition.rb
Overview
The definition of an option.
Instance Attribute Summary collapse
- 
  
    
      #argument  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute argument. 
- 
  
    
      #block  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute block. 
- 
  
    
      #default  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute default. 
- 
  
    
      #desc  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute desc. 
- 
  
    
      #hidden  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute hidden. 
- 
  
    
      #long  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute long. 
- 
  
    
      #multiple  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute multiple. 
- 
  
    
      #short  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute short. 
- 
  
    
      #transform  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute transform. 
Instance Method Summary collapse
- #formatted_name ⇒ Object
- 
  
    
      #initialize(short:, long:, desc:, argument:, multiple:, block:, hidden:, default:, transform:)  ⇒ OptionDefinition 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of OptionDefinition. 
- #to_h ⇒ Object
Constructor Details
#initialize(short:, long:, desc:, argument:, multiple:, block:, hidden:, default:, transform:) ⇒ OptionDefinition
Returns a new instance of OptionDefinition.
| 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # File 'lib/cri/option_definition.rb', line 16 def initialize(short:, long:, desc:, argument:, multiple:, block:, hidden:, default:, transform:) @short = short @long = long @desc = desc @argument = argument @multiple = multiple @block = block @hidden = hidden @default = default @transform = transform if @short.nil? && @long.nil? raise ArgumentError, 'short and long options cannot both be nil' end if @default && @argument == :forbidden raise ArgumentError, 'a default value cannot be specified for flag options' end @default = false if @argument == :forbidden end | 
Instance Attribute Details
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
| 9 10 11 | # File 'lib/cri/option_definition.rb', line 9 def argument @argument end | 
#block ⇒ Object (readonly)
Returns the value of attribute block.
| 11 12 13 | # File 'lib/cri/option_definition.rb', line 11 def block @block end | 
#default ⇒ Object (readonly)
Returns the value of attribute default.
| 13 14 15 | # File 'lib/cri/option_definition.rb', line 13 def default @default end | 
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
| 8 9 10 | # File 'lib/cri/option_definition.rb', line 8 def desc @desc end | 
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
| 12 13 14 | # File 'lib/cri/option_definition.rb', line 12 def hidden @hidden end | 
#long ⇒ Object (readonly)
Returns the value of attribute long.
| 7 8 9 | # File 'lib/cri/option_definition.rb', line 7 def long @long end | 
#multiple ⇒ Object (readonly)
Returns the value of attribute multiple.
| 10 11 12 | # File 'lib/cri/option_definition.rb', line 10 def multiple @multiple end | 
#short ⇒ Object (readonly)
Returns the value of attribute short.
| 6 7 8 | # File 'lib/cri/option_definition.rb', line 6 def short @short end | 
#transform ⇒ Object (readonly)
Returns the value of attribute transform.
| 14 15 16 | # File 'lib/cri/option_definition.rb', line 14 def transform @transform end | 
Instance Method Details
#formatted_name ⇒ Object
| 52 53 54 | # File 'lib/cri/option_definition.rb', line 52 def formatted_name @long ? '--' + @long : '-' + @short end | 
#to_h ⇒ Object
| 38 39 40 41 42 43 44 45 46 47 48 49 50 | # File 'lib/cri/option_definition.rb', line 38 def to_h { short: @short, long: @long, desc: @desc, argument: @argument, multiple: @multiple, block: @block, hidden: @hidden, default: @default, transform: @transform, } end |