Class: Naplug::Status
- Inherits:
-
Object
- Object
- Naplug::Status
- Includes:
- Comparable
- Defined in:
- lib/naplug/status.rb
Defined Under Namespace
Classes: InvalidStatus
Constant Summary collapse
- STATUS =
{ :ok => OpenStruct.new({ :i => 0, :s => 'OK', :y => '+' }), :warning => OpenStruct.new({ :i => 1, :s => 'WARNING', :y => '-' }), :critical => OpenStruct.new({ :i => 2, :s => 'CRITICAL', :y => '!' }), :unknown => OpenStruct.new({ :i => 3, :s => 'UNKNOWN', :y => '*' }) }
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(state = :unknown) ⇒ Status
constructor
A new instance of Status.
- #to_i ⇒ Object
- #to_s ⇒ Object
- #to_y ⇒ Object
Constructor Details
#initialize(state = :unknown) ⇒ Status
Returns a new instance of Status.
22 23 24 |
# File 'lib/naplug/status.rb', line 22 def initialize(state = :unknown) @status = state end |
Class Method Details
.states ⇒ Object
18 19 20 |
# File 'lib/naplug/status.rb', line 18 def self.states STATUS.keys end |
Instance Method Details
#<=>(other) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/naplug/status.rb', line 53 def <=>(other) case when self.to_i < other.to_i then -1 when self.to_i > other.to_i then 1 else 0 end end |
#to_i ⇒ Object
45 46 47 |
# File 'lib/naplug/status.rb', line 45 def to_i STATUS[@status].i end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/naplug/status.rb', line 41 def to_s STATUS[@status].s end |
#to_y ⇒ Object
49 50 51 |
# File 'lib/naplug/status.rb', line 49 def to_y STATUS[@status].y end |