Class: Oyster::Option
- Inherits:
-
Object
show all
- Defined in:
- lib/oyster/option.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, options = {}) ⇒ Option
Returns a new instance of Option.
12
13
14
15
16
|
# File 'lib/oyster/option.rb', line 12
def initialize(name, options = {})
@names = [name.to_sym]
@description = options[:desc] || ''
@settings = options
end
|
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
10
11
12
|
# File 'lib/oyster/option.rb', line 10
def description
@description
end
|
Class Method Details
.create(type, *args) ⇒ Object
4
5
6
7
8
|
# File 'lib/oyster/option.rb', line 4
def self.create(type, *args)
name = type.to_s.sub(/^(.)/) { |m| m.upcase } + 'Option'
klass = Oyster.const_get(name)
klass.new(*args)
end
|
Instance Method Details
#alternate(name) ⇒ Object
26
27
28
|
# File 'lib/oyster/option.rb', line 26
def alternate(name)
@names << name.to_sym unless has_name?(name) || name.nil?
end
|
#consume(list) ⇒ Object
30
|
# File 'lib/oyster/option.rb', line 30
def consume(list); end
|
#default_value(value = nil) ⇒ Object
32
33
34
|
# File 'lib/oyster/option.rb', line 32
def default_value(value = nil)
@settings[:default].nil? ? value : @settings[:default]
end
|
#has_name?(name) ⇒ Boolean
18
19
20
|
# File 'lib/oyster/option.rb', line 18
def has_name?(name)
name && @names.include?(name.to_sym)
end
|
#help_names ⇒ Object
36
37
38
39
|
# File 'lib/oyster/option.rb', line 36
def help_names
@names.map { |name| name.to_s }.sort.map {
|name| (name.size > 1 ? '--' : '-') + name }
end
|
#name ⇒ Object
22
23
24
|
# File 'lib/oyster/option.rb', line 22
def name
@names.first
end
|