Class: CommandLine::Flag
- Inherits:
-
Object
- Object
- CommandLine::Flag
- Defined in:
- lib/command_line/flag.rb
Overview
Argument flag handling.
Instance Attribute Summary collapse
-
#alias ⇒ Object
readonly
Returns the value of attribute alias.
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#expects_argument? ⇒ Boolean
Check if flag expects an argument (Are you talking to me?).
-
#has_alias? ⇒ Boolean
Check if flag has an alias.
-
#initialize(name, definition) ⇒ Flag
constructor
Initialize new Flag
nameThe name of the flagdefinitionThe definition of the flag. -
#optional? ⇒ Boolean
Check if flag is optional.
-
#required? ⇒ Boolean
Check if flag is required.
-
#to_alias ⇒ Object
Argument alias representation of the flag (-f).
-
#to_argument ⇒ Object
Argument representation of the flag (–fast).
Constructor Details
#initialize(name, definition) ⇒ Flag
Initialize new Flag name The name of the flag definition The definition of the flag.
13 14 15 16 17 18 |
# File 'lib/command_line/flag.rb', line 13 def initialize(name, definition) @name = name.to_s.gsub(/_/, '-').to_sym @alias = definition[:alias].to_sym if definition[:alias] @required = definition.has_key?(:required) && definition[:required] == true @argument = definition[:expects] if definition[:expects] end |
Instance Attribute Details
#alias ⇒ Object (readonly)
Returns the value of attribute alias.
7 8 9 |
# File 'lib/command_line/flag.rb', line 7 def alias @alias end |
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
8 9 10 |
# File 'lib/command_line/flag.rb', line 8 def argument @argument end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/command_line/flag.rb', line 6 def name @name end |
Instance Method Details
#expects_argument? ⇒ Boolean
Check if flag expects an argument (Are you talking to me?)
46 47 48 |
# File 'lib/command_line/flag.rb', line 46 def expects_argument? !@argument.nil? end |
#has_alias? ⇒ Boolean
Check if flag has an alias
31 32 33 |
# File 'lib/command_line/flag.rb', line 31 def has_alias? !@alias.nil? end |
#optional? ⇒ Boolean
Check if flag is optional
36 37 38 |
# File 'lib/command_line/flag.rb', line 36 def optional? !@required end |
#required? ⇒ Boolean
Check if flag is required
41 42 43 |
# File 'lib/command_line/flag.rb', line 41 def required? @required end |
#to_alias ⇒ Object
Argument alias representation of the flag (-f)
26 27 28 |
# File 'lib/command_line/flag.rb', line 26 def to_alias "-#{@alias}" end |
#to_argument ⇒ Object
Argument representation of the flag (–fast)
21 22 23 |
# File 'lib/command_line/flag.rb', line 21 def to_argument "--#{@name}" end |