Class: Zabbirc::Priority

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/zabbirc/priority.rb

Constant Summary collapse

PRIORITIES =
{
    0 => :not_classified,
    1 => :information,
    2 => :warning,
    3 => :average,
    4 => :high,
    5 => :disaster
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(priority) ⇒ Priority

Returns a new instance of Priority.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/zabbirc/priority.rb', line 15

def initialize priority
  case priority
  when String, Symbol
    raise ArgumentError, "unknown priority `#{priority}`" unless PRIORITIES.key(priority.to_sym)
    @number = PRIORITIES.key(priority.to_sym)
    @code = priority.to_sym
  when Integer
    raise ArgumentError, "unknown priority `#{priority}`" unless PRIORITIES[priority]
    @number = priority
    @code = PRIORITIES[@number]
  else
    raise ArgumentError, "cannot create priority from `#{priority}` of class `#{priority.class}`"
  end
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



14
15
16
# File 'lib/zabbirc/priority.rb', line 14

def code
  @code
end

#numberObject (readonly)

Returns the value of attribute number.



14
15
16
# File 'lib/zabbirc/priority.rb', line 14

def number
  @number
end

Instance Method Details

#<=>(other) ⇒ Object



30
31
32
# File 'lib/zabbirc/priority.rb', line 30

def <=> other
  number <=> other.number
end

#to_sObject



34
35
36
# File 'lib/zabbirc/priority.rb', line 34

def to_s
  code.to_s
end