Class: Miniparse::FlagOption

Inherits:
Option show all
Defined in:
lib/miniparse/command.rb

Instance Attribute Summary

Attributes inherited from Option

#shortable, #value

Attributes inherited from Command

#desc, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Option

#parse_value

Methods inherited from Command

#help_desc, #initialize, #run, valid_spec

Constructor Details

This class inherits a constructor from Miniparse::Command

Class Method Details

.spec_to_name(spec) ⇒ Object



175
176
177
# File 'lib/miniparse/command.rb', line 175

def self.spec_to_name(spec)
  spec_pattern_to_name(spec, /\A--(\w[\w-]+)[=| ]\S+\z/)
end

Instance Method Details

#arg_to_value(arg) ⇒ Object



186
187
188
189
190
191
192
193
194
# File 'lib/miniparse/command.rb', line 186

def arg_to_value(arg)
  if arg =~ /\A--#{name}[=| ](.+)\z/
    $1
  elsif shortable && (arg =~ /\A-#{name.to_s[0]}[=| ](.+)\z/)
    $1
  else
    nil
  end
end

#check(arg) ⇒ Object

Returns true if arg specifies this option.

Parameters:

  • arg

    is like an ARGV element

Returns:

  • true if arg specifies this option



181
182
183
184
# File 'lib/miniparse/command.rb', line 181

def check(arg)
   super(arg) || (arg =~ /\A--#{name}\z/) ||
    (shortable && (arg =~ /\A-#{name.to_s[0]}\z/))
end

#help_usageObject



196
197
198
# File 'lib/miniparse/command.rb', line 196

def help_usage
  "[#{spec}]"
end