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(opts = {}) ⇒ Flag

Constructs a new Flag.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :label (String)
  • :flavor (Symbol)

    `:anchor`, `:long`, `:short`.



30
31
32
33
# File 'lib/term_utils/ap/flag.rb', line 30

def initialize(opts = {})
  @label = opts.fetch(:label, nil)
  @flavor = opts.fetch(:flavor, nil)
end

Instance Attribute Details

#flavorSymbol

Returns `:anchor`, `:long`, `:short`.

Returns:

  • (Symbol)

    `:anchor`, `:long`, `:short`.



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

def flavor
  @flavor
end

#labelString

Returns:

  • (String)


23
24
25
# File 'lib/term_utils/ap/flag.rb', line 23

def label
  @label
end

Instance Method Details

#to_sString

Returns the string representation of this one.

Returns:

  • (String)


36
37
38
39
40
41
42
43
44
45
# File 'lib/term_utils/ap/flag.rb', line 36

def to_s
  case @flavor
  when :anchor
    @label
  when :long
    "--%s" % @label
  when :short
    "-%s" % @label
  end
end