Class: Departure::Option
- Inherits:
-
Object
- Object
- Departure::Option
- Defined in:
- lib/departure/option.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.from_string(string) ⇒ Option
Builds an instance by parsing its name and value out of the given string.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compares two options.
-
#hash ⇒ Fixnum
Returns the option’s hash.
-
#initialize(name, value = nil) ⇒ Option
constructor
Constructor.
-
#to_s ⇒ String
Returns the option as string following the “–<name>=<value>” format or the short “-n=value” format.
Constructor Details
#initialize(name, value = nil) ⇒ Option
Constructor
18 19 20 21 |
# File 'lib/departure/option.rb', line 18 def initialize(name, value = nil) @name = normalize_option(name) @value = value end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/departure/option.rb', line 3 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/departure/option.rb', line 3 def value @value end |
Class Method Details
.from_string(string) ⇒ Option
Builds an instance by parsing its name and value out of the given string.
9 10 11 12 |
# File 'lib/departure/option.rb', line 9 def self.from_string(string) name, value = string.split(/\s|=/, 2) new(name, value) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compares two options
27 28 29 |
# File 'lib/departure/option.rb', line 27 def ==(other) name == other.name end |
#hash ⇒ Fixnum
Returns the option’s hash
35 36 37 |
# File 'lib/departure/option.rb', line 35 def hash name.hash end |
#to_s ⇒ String
Returns the option as string following the “–<name>=<value>” format or the short “-n=value” format
43 44 45 |
# File 'lib/departure/option.rb', line 43 def to_s "#{name}#{value_as_string}" end |