class TermUtils::AP::Flag

Represents a Flag.

Attributes

flavor[R]

@return [Symbol] `:long`, `:short`.

label[R]

@return [String]

Public Class Methods

new(label, flavor) click to toggle source

Constructs a new Flag. @param label [String] @param flavor [Symbol] `:short`, `:long`.

# 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

Public Instance Methods

==(other) click to toggle source

Tests whether this one is equal to a given Flag.

# 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?() click to toggle source

Tests whether this one represents a long flag. @return [Boolean]

# File lib/term_utils/ap/flag.rb, line 48
def long?
  @flavor == :long
end
short?() click to toggle source

Tests whether this one represents a short flag. @return [Boolean]

# File lib/term_utils/ap/flag.rb, line 54
def short?
  @flavor == :short
end
to_s() click to toggle source

Returns the string representation of this one. @return [String]

# File lib/term_utils/ap/flag.rb, line 60
def to_s
  @label
end