Class: Collins::Power
- Inherits:
-
Object
show all
- Includes:
- Util
- Defined in:
- lib/collins/power.rb
Constant Summary
Util::Logging::DEFAULT_LOG_FORMAT
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util
#deep_copy_hash, #get_asset_or_tag, included, #require_non_empty, #require_that, #stringify_hash, #symbolize_hash
#get_logger
Constructor Details
#initialize(model = {}) ⇒ Power
Returns a new instance of Power.
72
73
74
75
76
77
78
79
|
# 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
|
Instance Attribute Details
#unit_id ⇒ Object
Returns the value of attribute unit_id.
38
39
40
|
# File 'lib/collins/power.rb', line 38
def unit_id
@unit_id
end
|
#units ⇒ Object
Returns the value of attribute units.
38
39
40
|
# File 'lib/collins/power.rb', line 38
def units
@units
end
|
Class Method Details
.from_json(json) ⇒ Object
41
42
43
44
45
46
47
|
# 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
|
.normalize_action(action) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# 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
|
Instance Method Details
#keys ⇒ Object
81
82
83
|
# File 'lib/collins/power.rb', line 81
def keys
units.map{|u| u.key }
end
|
#labels ⇒ Object
90
91
92
|
# File 'lib/collins/power.rb', line 90
def labels
units.map{|u| u.label}
end
|
#positions ⇒ Object
93
94
95
|
# File 'lib/collins/power.rb', line 93
def positions
units.map{|u| u.position}
end
|
#types ⇒ Object
87
88
89
|
# File 'lib/collins/power.rb', line 87
def types
units.map{|u| u.type}
end
|
#values ⇒ Object
84
85
86
|
# File 'lib/collins/power.rb', line 84
def values
units.map{|u| u.value}
end
|