class Collins::Power
Attributes
unit_id[RW]
units[RW]
Public Class Methods
from_json(json)
click to toggle source
# File lib/collins/power.rb, line 41 def from_json json return [] if (json.nil? or json.empty?) if not json.is_a?(Array) then json = [json] end json.map { |j| Collins::Power.new j } end
new(model = {})
click to toggle source
# File lib/collins/power.rb, line 72 def initialize model = {} hash = symbolize_hash(model).inject({}) do |result, (k,v)| result[k.downcase] = v result end @unit_id = hash[:unit_id].to_s.to_i @units = (hash[:units] || []).map {|u| Collins::PowerUnit.new(u)} end
normalize_action(action)
click to toggle source
# File lib/collins/power.rb, line 48 def normalize_action action case action.to_s.downcase.to_sym when :off, :poweroff "powerOff" when :on, :poweron "powerOn" when :powersoft "powerSoft" when :soft, :rebootsoft "rebootSoft" when :hard, :reboothard "rebootHard" when :status, :powerstate "powerState" when :verify "verify" when :identify "identify" else raise InvalidPowerStatus.new("#{action} is not a valid power status") end end
Public Instance Methods
keys()
click to toggle source
# File lib/collins/power.rb, line 81 def keys units.map{|u| u.key } end
labels()
click to toggle source
# File lib/collins/power.rb, line 90 def labels units.map{|u| u.label} end
positions()
click to toggle source
# File lib/collins/power.rb, line 93 def positions units.map{|u| u.position} end
types()
click to toggle source
# File lib/collins/power.rb, line 87 def types units.map{|u| u.type} end
values()
click to toggle source
# File lib/collins/power.rb, line 84 def values units.map{|u| u.value} end