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
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.
10 11 12 |
# File 'lib/emu_power/commands.rb', line 10 def initialize(name) @data = { name: name } end |
Instance Method Details
#to_command ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/emu_power/commands.rb', line 14 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
30 31 32 |
# File 'lib/emu_power/commands.rb', line 30 def to_hex(i, width = 8) return "0x%0#{width}x" % i end |
#to_yn(bool) ⇒ Object
Convert bool to Y or N
25 26 27 |
# File 'lib/emu_power/commands.rb', line 25 def to_yn(bool) return bool ? 'Y' : 'N' end |