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
#initialize(**attributes) ⇒ Flag
Returns a new instance of Flag.
6 |
# File 'lib/hashira/cli/flag.rb', line 6 def initialize(**attributes) = super(arg: nil, default: "", field: nil, parse: nil, mode: nil, **attributes) |
Instance Attribute Details
#arg ⇒ Object (readonly)
Returns the value of attribute arg
4 5 6 |
# File 'lib/hashira/cli/flag.rb', line 4 def arg @arg end |
#default ⇒ Object (readonly)
Returns the value of attribute default
4 5 6 |
# File 'lib/hashira/cli/flag.rb', line 4 def default @default end |
#field ⇒ Object (readonly)
Returns the value of attribute field
4 5 6 |
# File 'lib/hashira/cli/flag.rb', line 4 def field @field end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode
4 5 6 |
# File 'lib/hashira/cli/flag.rb', line 4 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name
4 5 6 |
# File 'lib/hashira/cli/flag.rb', line 4 def name @name end |
#parse ⇒ Object (readonly)
Returns the value of attribute parse
4 5 6 |
# File 'lib/hashira/cli/flag.rb', line 4 def parse @parse end |
#text ⇒ Object (readonly)
Returns the value of attribute text
4 5 6 |
# File 'lib/hashira/cli/flag.rb', line 4 def text @text end |
Instance Method Details
#bid(value) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/hashira/cli/flag.rb', line 15 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
23 |
# File 'lib/hashira/cli/flag.rb', line 23 def label = [name, arg].compact.join(" ") |
#names ⇒ Object
25 |
# File 'lib/hashira/cli/flag.rb', line 25 def names = name.split(", ") |
#page? ⇒ Boolean
27 |
# File 'lib/hashira/cli/flag.rb', line 27 def page? = Hashira::CLI::Usage::PAGES.include?(mode) |
#read(arguments) ⇒ Object
8 |
# File 'lib/hashira/cli/flag.rb', line 8 def read(arguments) = arg ? take(arguments) : arguments.delete(name) |
#take(arguments) ⇒ Object
10 11 12 13 |
# File 'lib/hashira/cli/flag.rb', line 10 def take(arguments) raw = arguments.take(name, default) parse ? parse.parse(raw) : raw end |