Class: XOptionParser::Switch::SummarizeArgument
- Inherits:
-
XOptionParser::Switch
- Object
- OptionParser::Switch
- XOptionParser::Switch
- XOptionParser::Switch::SummarizeArgument
- Defined in:
- lib/xoptparse.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arg_parameters ⇒ Object
readonly
Returns the value of attribute arg_parameters.
Instance Method Summary collapse
-
#initialize ⇒ SummarizeArgument
constructor
A new instance of SummarizeArgument.
- #match_nonswitch? ⇒ Boolean
- #summarize ⇒ Object
- #switch_name ⇒ Object
Constructor Details
#initialize ⇒ SummarizeArgument
165 166 167 168 169 170 171 |
# File 'lib/xoptparse.rb', line 165 def initialize(*) super @arg_parameters = arg.scan(/\[\s*(.*?)\s*\]|(\S+)/).map do |opt, req| name = opt || req [name.sub(/\s*\.\.\.$/, ''), opt ? :opt : :req, name.end_with?('...') ? :rest : nil] end end |
Instance Attribute Details
#arg_parameters ⇒ Object (readonly)
Returns the value of attribute arg_parameters.
163 164 165 |
# File 'lib/xoptparse.rb', line 163 def arg_parameters @arg_parameters end |
Instance Method Details
#match_nonswitch? ⇒ Boolean
186 187 188 |
# File 'lib/xoptparse.rb', line 186 def match_nonswitch?(*) super if @pattern.is_a?(Regexp) end |
#summarize ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/xoptparse.rb', line 173 def summarize(*) original_arg = arg @short = arg_parameters.map do |name, type, rest| var = "#{name}#{rest ? '...' : ''}" type == :req ? var : "[#{var}]" end @arg = nil res = super @arg = original_arg @short = nil res end |
#switch_name ⇒ Object
190 191 192 |
# File 'lib/xoptparse.rb', line 190 def switch_name arg_parameters.first.first end |