Class: Toys::FlagGroup::Base
- Inherits:
-
Object
- Object
- Toys::FlagGroup::Base
- Defined in:
- toys-core/lib/toys/flag_group.rb
Overview
Defined in the toys-core gem
The base class of a FlagGroup, implementing everything except validation. The base class effectively behaves as an Optional group. And the default group that contains flags not otherwise assigned to a group, is of this type. However, you should use Optional when creating an explicit optional group.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#desc ⇒ Toys::WrappableString
The short description string.
-
#flags ⇒ Array<Toys::Flag>
readonly
An array of flags that are in this group.
-
#long_desc ⇒ Array<Toys::WrappableString>
The long description strings.
-
#name ⇒ String, ...
readonly
The symbolic name for this group.
Instance Method Summary collapse
-
#append_long_desc(long_desc) ⇒ self
Append long description strings.
-
#empty? ⇒ Boolean
Returns true if this group is empty.
-
#summary ⇒ String
Returns a string summarizing this group.
Instance Attribute Details
#desc ⇒ Toys::WrappableString
The short description string.
When reading, this is always returned as a WrappableString.
When setting, the description may be provided as any of the following:
- A WrappableString.
- A normal String, which will be transformed into a WrappableString using spaces as word delimiters.
- An Array of String, which will be transformed into a WrappableString where each array element represents an individual word for wrapping.
93 94 95 |
# File 'toys-core/lib/toys/flag_group.rb', line 93 def desc @desc end |
#flags ⇒ Array<Toys::Flag> (readonly)
An array of flags that are in this group. Do not modify the returned array.
119 120 121 |
# File 'toys-core/lib/toys/flag_group.rb', line 119 def flags @flags end |
#long_desc ⇒ Array<Toys::WrappableString>
The long description strings.
When reading, this is returned as an Array of WrappableString representing the lines in the description.
When setting, the description must be provided as an Array where each element may be any of the following:
- A WrappableString representing one line.
- A normal String representing a line. This will be transformed into a WrappableString using spaces as word delimiters.
- An Array of String representing a line. This will be transformed into a WrappableString where each array element represents an individual word for wrapping.
112 113 114 |
# File 'toys-core/lib/toys/flag_group.rb', line 112 def long_desc @long_desc end |
#name ⇒ String, ... (readonly)
The symbolic name for this group
76 77 78 |
# File 'toys-core/lib/toys/flag_group.rb', line 76 def name @name end |
Instance Method Details
#append_long_desc(long_desc) ⇒ self
Append long description strings.
You must pass an array of lines in the long description. See #long_desc for details on how each line may be represented.
170 171 172 173 |
# File 'toys-core/lib/toys/flag_group.rb', line 170 def append_long_desc(long_desc) @long_desc.concat(WrappableString.make_array(long_desc)) self end |
#empty? ⇒ Boolean
Returns true if this group is empty
125 126 127 |
# File 'toys-core/lib/toys/flag_group.rb', line 125 def empty? flags.empty? end |
#summary ⇒ String
Returns a string summarizing this group. This is generally either the short description or a representation of all the flags included.
134 135 136 137 |
# File 'toys-core/lib/toys/flag_group.rb', line 134 def summary return desc.to_s.inspect unless desc.empty? flags.map(&:display_name).inspect end |