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.



116
117
118
119
120
121
122
# File 'lib/cli/dsl.rb', line 116

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)


126
127
128
# File 'lib/cli/dsl.rb', line 126

def has_short?
	@options.member? :short
end

#shortObject



130
131
132
# File 'lib/cli/dsl.rb', line 130

def short
	@options[:short]
end

#switchObject



134
135
136
# File 'lib/cli/dsl.rb', line 134

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

#switch_shortObject



138
139
140
# File 'lib/cli/dsl.rb', line 138

def switch_short
	'-' + short.to_s
end

#to_sObject



142
143
144
# File 'lib/cli/dsl.rb', line 142

def to_s
	switch
end