Class: Commander::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/commander-tool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(switches, description = "") ⇒ Option

Returns a new instance of Option.



36
37
38
39
40
41
42
43
# File 'lib/commander-tool.rb', line 36

def initialize(switches, description = "")
  @switches = switches
  @description = description

  @key =
    switches.find { |s| s.start_with?("--") }&.sub(/^--/, "")&.tr("-", "_") ||
    switches.find { |s| s.start_with?("-") }&.sub(/^-/, "")
end

Instance Attribute Details

#description ⇒ Object (readonly)

Returns the value of attribute description.



34
35
36
# File 'lib/commander-tool.rb', line 34

def description
  @description
end

#key ⇒ Object (readonly)

Returns the value of attribute key.



34
35
36
# File 'lib/commander-tool.rb', line 34

def key
  @key
end

#switches ⇒ Object (readonly)

Returns the value of attribute switches.



34
35
36
# File 'lib/commander-tool.rb', line 34

def switches
  @switches
end

Instance Method Details

#matches?(arg) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/commander-tool.rb', line 45

def matches?(arg)
  @switches.include?(arg)
end

#value_required? ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/commander-tool.rb', line 49

def value_required?
  @description.include?("<") ||
    @description.include?("argument") ||
    @description.include?("value")
end