Class: EmuPower::Commands::Command
- Inherits:
-
Object
- Object
- EmuPower::Commands::Command
- Defined in:
- lib/emu_power/commands.rb
Overview
Base class that all commands inherit from
Direct Known Subclasses
GetCurrentSummation, GetInstantaneousDemand, GetMessage, GetNetworkInfo, GetNetworkStatus, GetPrice, GetSchedule, SetSchedule
Instance Method Summary collapse
-
#initialize(name) ⇒ Command
constructor
A new instance of Command.
- #to_command ⇒ Object
-
#to_hex(i, width = 8) ⇒ Object
Convert int to 0xABCD hex.
-
#to_yn(bool) ⇒ Object
Convert bool to Y or N.
Constructor Details
#initialize(name) ⇒ Command
Returns a new instance of Command.
9 10 11 |
# File 'lib/emu_power/commands.rb', line 9 def initialize(name) @data = { name: name } end |
Instance Method Details
#to_command ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/emu_power/commands.rb', line 13 def to_command = @data.map do |k, v| tag = k.to_s.capitalize next "<#{tag}>#{v}</#{tag}>" end return "<Command>#{.join}</Command>" end |
#to_hex(i, width = 8) ⇒ Object
Convert int to 0xABCD hex
29 30 31 |
# File 'lib/emu_power/commands.rb', line 29 def to_hex(i, width = 8) return "0x%0#{width}x" % i end |
#to_yn(bool) ⇒ Object
Convert bool to Y or N
24 25 26 |
# File 'lib/emu_power/commands.rb', line 24 def to_yn(bool) return bool ? 'Y' : 'N' end |