Class: Hashira::CLI::Flag
- Inherits:
-
Data
- Object
- Data
- Hashira::CLI::Flag
- Defined in:
- lib/hashira/cli/flag.rb
Instance Attribute Summary collapse
-
#arg ⇒ Object
readonly
Returns the value of attribute arg.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parse ⇒ Object
readonly
Returns the value of attribute parse.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #bid(value) ⇒ Object
-
#initialize(**attributes) ⇒ Flag
constructor
A new instance of Flag.
- #label ⇒ Object
- #names ⇒ Object
- #page? ⇒ Boolean
- #read(arguments) ⇒ Object
- #take(arguments) ⇒ Object
Constructor Details
Instance Attribute Details
#arg ⇒ Object (readonly)
Returns the value of attribute arg
6 7 8 |
# File 'lib/hashira/cli/flag.rb', line 6 def arg @arg end |
#default ⇒ Object (readonly)
Returns the value of attribute default
6 7 8 |
# File 'lib/hashira/cli/flag.rb', line 6 def default @default end |
#field ⇒ Object (readonly)
Returns the value of attribute field
6 7 8 |
# File 'lib/hashira/cli/flag.rb', line 6 def field @field end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode
6 7 8 |
# File 'lib/hashira/cli/flag.rb', line 6 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name
6 7 8 |
# File 'lib/hashira/cli/flag.rb', line 6 def name @name end |
#parse ⇒ Object (readonly)
Returns the value of attribute parse
6 7 8 |
# File 'lib/hashira/cli/flag.rb', line 6 def parse @parse end |
#text ⇒ Object (readonly)
Returns the value of attribute text
6 7 8 |
# File 'lib/hashira/cli/flag.rb', line 6 def text @text end |
Instance Method Details
#bid(value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/hashira/cli/flag.rb', line 17 def bid(value) case [mode, value] in [nil, _] | [_, nil] | [_, []] then nil in [:parsed, chosen] then ["#{name} #{chosen}", chosen] else [name, mode] end end |
#label ⇒ Object
25 |
# File 'lib/hashira/cli/flag.rb', line 25 def label = [name, arg].compact.join(" ") |
#names ⇒ Object
27 |
# File 'lib/hashira/cli/flag.rb', line 27 def names = name.split(", ") |
#page? ⇒ Boolean
29 |
# File 'lib/hashira/cli/flag.rb', line 29 def page? = Hashira::CLI::Usage::PAGES.include?(mode) |
#read(arguments) ⇒ Object
10 |
# File 'lib/hashira/cli/flag.rb', line 10 def read(arguments) = arg ? take(arguments) : arguments.delete(name) |
#take(arguments) ⇒ Object
12 13 14 15 |
# File 'lib/hashira/cli/flag.rb', line 12 def take(arguments) raw = arguments.take(name, default) parse ? parse.parse(raw) : raw end |