Class: Pyer::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/pyer/options.rb

Overview

Option class

Direct Known Subclasses

Flag, Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, &block) ⇒ Option

Incapsulate internal option information, mainly used to store option specific configuration data.

name - The String or Symbol option name. description - The String description text. block - An optional block.



289
290
291
292
293
294
295
296
297
298
# File 'lib/pyer/options.rb', line 289

def initialize(name, description, &block)
  # Remove leading '-' from name if any
  @name = name.to_s.gsub(/^--?/, '')
  fail InvalidOptionError, "Option #{@name} is invalid" if @name.size < 2
  @expects_argument = false
  @value = nil
  @short = @name[0]
  @description = description
  @callback = (block_given? ? block : nil)
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



279
280
281
# File 'lib/pyer/options.rb', line 279

def callback
  @callback
end

#descriptionObject (readonly)

Returns the value of attribute description.



279
280
281
# File 'lib/pyer/options.rb', line 279

def description
  @description
end

#expects_argumentObject (readonly)

Returns the value of attribute expects_argument.



280
281
282
# File 'lib/pyer/options.rb', line 280

def expects_argument
  @expects_argument
end

#nameObject (readonly)

Returns the value of attribute name.



279
280
281
# File 'lib/pyer/options.rb', line 279

def name
  @name
end

#shortObject (readonly)

Returns the value of attribute short.



279
280
281
# File 'lib/pyer/options.rb', line 279

def short
  @short
end

#valueObject

Returns the value of attribute value.



281
282
283
# File 'lib/pyer/options.rb', line 281

def value
  @value
end