Class: TermUtils::AP::Flag

Inherits:
Object
  • Object
show all
Defined in:
lib/term_utils/ap/flag.rb

Overview

Represents a Flag.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, flavor) ⇒ Flag

Constructs a new Flag.

Parameters:

  • label (String)
  • flavor (Symbol)

    `:short`, `:long`.

Raises:



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

#flavorSymbol (readonly)

Returns `:long`, `:short`.

Returns:

  • (Symbol)

    `:long`, `:short`.



26
27
28
# File 'lib/term_utils/ap/flag.rb', line 26

def flavor
  @flavor
end

#labelString (readonly)

Returns:

  • (String)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


54
55
56
# File 'lib/term_utils/ap/flag.rb', line 54

def short?
  @flavor == :short
end

#to_sString

Returns the string representation of this one.

Returns:

  • (String)


60
61
62
# File 'lib/term_utils/ap/flag.rb', line 60

def to_s
  @label
end