Class: Linen::Plugin::Argument

Inherits:
Object
  • Object
show all
Defined in:
lib/linen/argument.rb

Overview

Copyright 2007, LAIKA, Inc. #

#

Authors: #

* Ben Bleything <[email protected]>                    #

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugin, name, opts) ⇒ Argument

Returns a new instance of Argument.



13
14
15
16
17
18
19
# File 'lib/linen/argument.rb', line 13

def initialize( plugin, name, opts )
	@plugin     = plugin
	@name       = name
	@prompt     = opts[:prompt]     || "Please enter the value for #{@name}"
	@validation = opts[:validation] || /^\w+$/
	@conversion = opts[:conversion] || nil
end

Instance Attribute Details

#promptObject (readonly)

Returns the value of attribute prompt.



11
12
13
# File 'lib/linen/argument.rb', line 11

def prompt
  @prompt
end

Instance Method Details

#convert(value) ⇒ Object



22
23
24
25
# File 'lib/linen/argument.rb', line 22

def convert( value )
	return value unless @conversion
	return @conversion.call( value )
end

#validate(value) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/linen/argument.rb', line 28

def validate( value )
	if @validation.is_a? Proc
		result = @validation.call( value )
	else
		result = ( value =~ @validation )
	end

	raise Linen::Plugin::ArgumentError, "Value '#{value}' is invalid for #{@name}." unless result
	return value
end