Class: Samovar::Option
- Inherits:
-
Object
- Object
- Samovar::Option
- Defined in:
- lib/samovar/options.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(flags, description, key: nil, default: nil, value: nil) ⇒ Option
constructor
A new instance of Option.
- #parse(input) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(flags, description, key: nil, default: nil, value: nil) ⇒ Option
Returns a new instance of Option.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/samovar/options.rb', line 25 def initialize(flags, description, key: nil, default: nil, value: nil) @flags = Flags.new(flags) @description = description if key @key = key else @key = @flags.first.key end @default = default @value = value @value ||= true if @flags.boolean? end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
45 46 47 |
# File 'lib/samovar/options.rb', line 45 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
42 43 44 |
# File 'lib/samovar/options.rb', line 42 def description @description end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
41 42 43 |
# File 'lib/samovar/options.rb', line 41 def flags @flags end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
47 48 49 |
# File 'lib/samovar/options.rb', line 47 def key @key end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
43 44 45 |
# File 'lib/samovar/options.rb', line 43 def type @type end |
Instance Method Details
#parse(input) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/samovar/options.rb', line 49 def parse(input) if result = @flags.parse(input) @value.nil? ? result : @value else @default end end |
#to_a ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/samovar/options.rb', line 61 def to_a unless @default.nil? [@flags, @description, "Default: #{@default}"] else [@flags, @description] end end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/samovar/options.rb', line 57 def to_s @flags end |