Class: CLASP::FlagSpecification
- Inherits:
- 
      Object
      
        - Object
- CLASP::FlagSpecification
 
- Defined in:
- lib/clasp/specifications.rb
Overview
A class that represents the specification for a command-line flag
Instance Attribute Summary collapse
- 
  
    
      #aliases  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The flag’s aliases array. 
- 
  
    
      #extras  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The flag’s extras. 
- 
  
    
      #help  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The flag’s help string. 
- 
  
    
      #name  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The flag’s name string. 
Class Method Summary collapse
- 
  
    
      .Help(extras = nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    An instance of FlagSpecification that provides default ‘–help’ information. 
- 
  
    
      .Version(extras = nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    An instance of FlagSpecification that provides default ‘–version’ information. 
Instance Method Summary collapse
- 
  
    
      #==(rhs)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Compares instance against another FlagSpecification or against a name (String). 
- 
  
    
      #initialize(name, aliases, help, extras = nil)  ⇒ FlagSpecification 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Creates a FlagSpecification instance from the given name, aliases, and help. 
- 
  
    
      #to_s  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    String form of the flag. 
Constructor Details
#initialize(name, aliases, help, extras = nil) ⇒ FlagSpecification
Creates a FlagSpecification instance from the given name, aliases, and help
Signature
- 
Parameters - 
name(String) The name, or long-form, of the flag
- 
aliases(Array) 0 or more strings specifying short-form or option-value aliases
- 
help(String) The help string, which may benil
- 
extrasAn application-defined additional parameter. Ifnil, it is assigned an emptyHash
 
- 
| 72 73 74 75 76 77 78 | # File 'lib/clasp/specifications.rb', line 72 def initialize(name, aliases, help, extras = nil) @name = name @aliases = (aliases || []).select { |a| a and not a.empty? } @help = help @extras = extras || {} end | 
Instance Attribute Details
#aliases ⇒ Object (readonly)
The flag’s aliases array
| 83 84 85 | # File 'lib/clasp/specifications.rb', line 83 def aliases @aliases end | 
#extras ⇒ Object (readonly)
The flag’s extras
| 87 88 89 | # File 'lib/clasp/specifications.rb', line 87 def extras @extras end | 
#help ⇒ Object (readonly)
The flag’s help string
| 85 86 87 | # File 'lib/clasp/specifications.rb', line 85 def help @help end | 
#name ⇒ Object (readonly)
The flag’s name string
| 81 82 83 | # File 'lib/clasp/specifications.rb', line 81 def name @name end | 
Class Method Details
.Help(extras = nil) ⇒ Object
An instance of FlagSpecification that provides default ‘–help’ information
| 136 137 138 139 140 141 142 143 | # File 'lib/clasp/specifications.rb', line 136 def self.Help(extras = nil) h = @@Help_ return self.new(h.name, h.aliases, h.help, extras) if extras h end | 
.Version(extras = nil) ⇒ Object
An instance of FlagSpecification that provides default ‘–version’ information
| 146 147 148 149 150 151 152 153 | # File 'lib/clasp/specifications.rb', line 146 def self.Version(extras = nil) h = @@Version_ return self.new(h.name, h.aliases, h.help, extras) if extras h end | 
Instance Method Details
#==(rhs) ⇒ Object
Compares instance against another FlagSpecification or against a name (String)
| 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | # File 'lib/clasp/specifications.rb', line 116 def == rhs case rhs when self.class return self.eql? rhs when String return name == rhs else false end end | 
#to_s ⇒ Object
String form of the flag
| 90 91 92 93 | # File 'lib/clasp/specifications.rb', line 90 def to_s "{#{name}; aliases=#{aliases.join(', ')}; help='#{help}'; extras=#{extras}}" end |