Class: Apc4r::Status
- Inherits:
-
Object
- Object
- Apc4r::Status
- Defined in:
- lib/apc4r/status.rb
Overview
Instance Method Summary collapse
-
#estimated_load ⇒ Object
estimates the load, in watts, based on loadpct and nompower This may not be even close to accurate.
-
#initialize(cache_ttl = 0) ⇒ Status
constructor
Creates a Status object, which gives access to information related to the connected UPS device.
- #method_missing(sym, *args) ⇒ Object
-
#status ⇒ Object
fetches a hash of status information from the UPS device.
-
#to_s ⇒ Object
fetches a string represention of the UPS status.
Constructor Details
#initialize(cache_ttl = 0) ⇒ Status
Creates a Status object, which gives access to information related to the connected UPS device
cache_ttl is the number of seconds to cache status on an object leave blank to fetch information from the ups device on every call
21 22 23 |
# File 'lib/apc4r/status.rb', line 21 def initialize cache_ttl=0 @cache_ttl = cache_ttl end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/apc4r/status.rb', line 55 def method_missing sym, *args if status.has_key?(sym) status[sym] else super end end |
Instance Method Details
#estimated_load ⇒ Object
estimates the load, in watts, based on loadpct and nompower This may not be even close to accurate
41 42 43 |
# File 'lib/apc4r/status.rb', line 41 def estimated_load (loadpct / 100) * nompower end |
#status ⇒ Object
fetches a hash of status information from the UPS device
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/apc4r/status.rb', line 27 def status if @cache_ttl > 0 if @cached_at == nil || @cached_at < (Time.now - @cache_ttl) @status = fetch_status end else @status = fetch_status end @status end |
#to_s ⇒ Object
fetches a string represention of the UPS status
47 48 49 50 51 52 53 |
# File 'lib/apc4r/status.rb', line 47 def to_s result = "" status.each_pair do |k,v| result << "#{k} = #{v}\n" end result end |