class Arrival::Option
Attributes
name[R]
value[R]
Public Class Methods
from_string(string)
click to toggle source
Builds an instance by parsing its name and value out of the given string.
@param string [String] @return [Option]
# File lib/arrival/option.rb, line 9 def self.from_string(string) name, value = string.split(/\s|=/, 2) new(name, value) end
new(name, value = nil)
click to toggle source
Constructor
@param name [String] @param optional value [String]
# File lib/arrival/option.rb, line 18 def initialize(name, value = nil) @name = normalize_option(name) @value = value end
Public Instance Methods
==(other)
click to toggle source
Compares two options
@param [Option] @return [Boolean]
# File lib/arrival/option.rb, line 27 def ==(other) name == other.name end
Also aliased as: eql?
hash()
click to toggle source
Returns the option's hash
@return [Fixnum]
# File lib/arrival/option.rb, line 35 def hash name.hash end
to_s()
click to toggle source
Returns the option as string following the “–<name>=<value>” format or the short “-n=value” format
@return [String]
# File lib/arrival/option.rb, line 43 def to_s "#{name}#{value_as_string}" end
Private Instance Methods
normalize_option(name)
click to toggle source
Returns the option name in “long” format, e.g., “–name”
@return [String]
# File lib/arrival/option.rb, line 52 def normalize_option(name) if name.start_with?('-') name elsif name.length == 1 "-#{name}" else "--#{name}" end end
value_as_string()
click to toggle source
Returns the value fragment of the option string if any value is specified
@return [String]
# File lib/arrival/option.rb, line 65 def value_as_string if value.nil? '' elsif value.include?('=') " #{value}" else "=#{value}" end end