Class: CLASP::FlagSpecification

Inherits:
Object
  • Object
show all
Defined in:
lib/clasp/specifications.rb

Overview

A class that represents the specification for a command-line flag

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, aliases, help, extras = nil) ⇒ FlagSpecification

Creates a FlagSpecification instance from the given name, aliases, and help

Signature

  • Parameters

    • name (String) The name, or long-form, of the flag

    • aliases (Array) 0 or more strings specifying short-form or option-value aliases

    • help (String) The help string, which may be nil

    • extras An application-defined additional parameter. If nil, it is assigned an empty Hash



72
73
74
75
76
77
78
# File 'lib/clasp/specifications.rb', line 72

def initialize(name, aliases, help, extras = nil)

	@name			=	name
	@aliases		=	(aliases || []).select { |a| a and not a.empty? }
	@help			=	help
	@extras			=	extras || {}
end

Instance Attribute Details

#aliasesObject (readonly)

The flag’s aliases array



83
84
85
# File 'lib/clasp/specifications.rb', line 83

def aliases
  @aliases
end

#extrasObject (readonly)

The flag’s extras



87
88
89
# File 'lib/clasp/specifications.rb', line 87

def extras
  @extras
end

#helpObject (readonly)

The flag’s help string



85
86
87
# File 'lib/clasp/specifications.rb', line 85

def help
  @help
end

#nameObject (readonly)

The flag’s name string



81
82
83
# File 'lib/clasp/specifications.rb', line 81

def name
  @name
end

Class Method Details

.Help(extras = nil) ⇒ Object

An instance of FlagSpecification that provides default ‘–help’ information



136
137
138
139
140
141
142
143
# File 'lib/clasp/specifications.rb', line 136

def self.Help(extras = nil)

	h = @@Help_

	return self.new(h.name, h.aliases, h.help, extras) if extras

	h
end

.Version(extras = nil) ⇒ Object

An instance of FlagSpecification that provides default ‘–version’ information



146
147
148
149
150
151
152
153
# File 'lib/clasp/specifications.rb', line 146

def self.Version(extras = nil)

	h = @@Version_

	return self.new(h.name, h.aliases, h.help, extras) if extras

	h
end

Instance Method Details

#==(rhs) ⇒ Object

Compares instance against another FlagSpecification or against a name (String)



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/clasp/specifications.rb', line 116

def == rhs

	case rhs
	when self.class

		return self.eql? rhs
	when String

		return name == rhs
	else

		false
	end
end

#to_sObject

String form of the flag



90
91
92
93
# File 'lib/clasp/specifications.rb', line 90

def to_s

	"{#{name}; aliases=#{aliases.join(', ')}; help='#{help}'; extras=#{extras}}"
end