Class: CLI::DSL::Switch

Inherits:
Base
  • Object
show all
Includes:
Description
Defined in:
lib/cli/dsl.rb

Direct Known Subclasses

Option

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods included from Description

#description, #description?

Constructor Details

#initialize(name, options = {}) ⇒ Switch

Returns a new instance of Switch.



137
138
139
140
141
142
143
# File 'lib/cli/dsl.rb', line 137

def initialize(name, options = {})
  super(name, options)
  if short = options[:short]
    raise ParserError::ShortNameNotSymbolError.new(self, short) if not short.is_a? Symbol
    raise ParserError::ShortNameIsInvalidError.new(self, short) if short.to_s.length > 1
  end
end

Instance Method Details

#has_short?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/cli/dsl.rb', line 147

def has_short?
  @options.member? :short
end

#shortObject



151
152
153
# File 'lib/cli/dsl.rb', line 151

def short
  @options[:short]
end

#switchObject



155
156
157
# File 'lib/cli/dsl.rb', line 155

def switch
  '--' + name.to_s.tr('_', '-')
end

#switch_shortObject



159
160
161
# File 'lib/cli/dsl.rb', line 159

def switch_short
  '-' + short.to_s
end

#to_sObject



163
164
165
# File 'lib/cli/dsl.rb', line 163

def to_s
  switch
end