Class: Linen::Plugin::Argument
- Inherits:
-
Object
- Object
- Linen::Plugin::Argument
- Defined in:
- lib/linen/argument.rb
Overview
Instance Attribute Summary collapse
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
Instance Method Summary collapse
- #convert(value) ⇒ Object
-
#initialize(plugin, name, opts) ⇒ Argument
constructor
A new instance of Argument.
- #validate(value) ⇒ Object
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
#prompt ⇒ Object (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 |