Class: Shellissimo::CommandName
- Inherits:
-
Object
- Object
- Shellissimo::CommandName
- Includes:
- Comparable
- Defined in:
- lib/shellissimo/command_name.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(name, aliases = []) ⇒ CommandName
constructor
A new instance of CommandName.
- #to_s ⇒ Object
Constructor Details
#initialize(name, aliases = []) ⇒ CommandName
Returns a new instance of CommandName.
8 9 10 11 |
# File 'lib/shellissimo/command_name.rb', line 8 def initialize(name, aliases = []) raise ArgumentError, "command name can't be blank" if String(name).empty? @name, @aliases = name.to_sym, Array(aliases).map(&:to_sym) end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
6 7 8 |
# File 'lib/shellissimo/command_name.rb', line 6 def aliases @aliases end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/shellissimo/command_name.rb', line 6 def name @name end |
Instance Method Details
#<=>(other) ⇒ Object
33 34 35 |
# File 'lib/shellissimo/command_name.rb', line 33 def <=>(other) self == other or name <=> other.name end |
#==(other) ⇒ Object Also known as: eql?
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/shellissimo/command_name.rb', line 17 def ==(other) case other when CommandName return true if other.equal? self return true if name == other.name && aliases == other.aliases false when String, Symbol return true if other.to_sym == @name return true if @aliases.include?(other.to_sym) false else false end end |
#hash ⇒ Object
13 14 15 |
# File 'lib/shellissimo/command_name.rb', line 13 def hash @name.hash ^ @aliases.hash end |
#to_s ⇒ Object
37 38 39 40 41 |
# File 'lib/shellissimo/command_name.rb', line 37 def to_s result = "\e[1m#{name}\e[0m" result += " (aliases: #{aliases.join(", ")})" unless aliases.empty? result end |