Class: Departure::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/departure/option.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = nil) ⇒ Option

Constructor

Parameters:

  • name (String)
  • optional

    value [String]



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

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/departure/option.rb', line 3

def name
  @name
end

#valueObject (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.

Parameters:

  • string (String)

Returns:



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

Parameters:

Returns:

  • (Boolean)


27
28
29
# File 'lib/departure/option.rb', line 27

def ==(other)
  name == other.name
end

#hashFixnum

Returns the option’s hash

Returns:

  • (Fixnum)


35
36
37
# File 'lib/departure/option.rb', line 35

def hash
  name.hash
end

#to_sString

Returns the option as string following the “–<name>=<value>” format or the short “-n=value” format

Returns:

  • (String)


43
44
45
# File 'lib/departure/option.rb', line 43

def to_s
  "#{name}#{value_as_string}"
end