Class: TermUtils::AP::Flag
- Inherits:
 - 
      Object
      
        
- Object
 - TermUtils::AP::Flag
 
 
- Defined in:
 - lib/term_utils/ap/flag.rb
 
Overview
Represents a Flag.
Instance Attribute Summary collapse
- 
  
    
      #flavor  ⇒ Symbol 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
‘:long`, `:short`.
 - #label ⇒ String readonly
 
Instance Method Summary collapse
- 
  
    
      #==(other)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Tests whether this one is equal to a given Flag.
 - 
  
    
      #initialize(label, flavor)  ⇒ Flag 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Constructs a new Flag.
 - 
  
    
      #long?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Tests whether this one represents a long flag.
 - 
  
    
      #short?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Tests whether this one represents a short flag.
 - 
  
    
      #to_s  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the string representation of this one.
 
Constructor Details
#initialize(label, flavor) ⇒ Flag
Constructs a new Flag.
      31 32 33 34 35 36 37  | 
    
      # File 'lib/term_utils/ap/flag.rb', line 31 def initialize(label, flavor) raise TermUtils::AP::SyntaxError, 'wrong flag label' if !label.is_a?(String) || /^-+$/.match?(label) || !/^-[0-9A-Za-z_-]+$/.match?(label) raise TermUtils::AP::SyntaxError, '' unless %i[short long].include?(flavor) @label = label @flavor = flavor end  | 
  
Instance Attribute Details
#flavor ⇒ Symbol (readonly)
Returns ‘:long`, `:short`.
      26 27 28  | 
    
      # File 'lib/term_utils/ap/flag.rb', line 26 def flavor @flavor end  | 
  
#label ⇒ String (readonly)
      24 25 26  | 
    
      # File 'lib/term_utils/ap/flag.rb', line 24 def label @label end  | 
  
Instance Method Details
#==(other) ⇒ Object
Tests whether this one is equal to a given Flag.
      40 41 42 43 44  | 
    
      # File 'lib/term_utils/ap/flag.rb', line 40 def ==(other) return false unless other.is_a?(TermUtils::AP::Flag) @label == other.label end  | 
  
#long? ⇒ Boolean
Tests whether this one represents a long flag.
      48 49 50  | 
    
      # File 'lib/term_utils/ap/flag.rb', line 48 def long? @flavor == :long end  | 
  
#short? ⇒ Boolean
Tests whether this one represents a short flag.
      54 55 56  | 
    
      # File 'lib/term_utils/ap/flag.rb', line 54 def short? @flavor == :short end  | 
  
#to_s ⇒ String
Returns the string representation of this one.
      60 61 62  | 
    
      # File 'lib/term_utils/ap/flag.rb', line 60 def to_s @label end  |