Class: EmuPower::Commands::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/emu_power/commands.rb

Overview

Base class that all commands inherit from

Instance Method Summary collapse

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_commandObject



13
14
15
16
17
18
19
20
21
# File 'lib/emu_power/commands.rb', line 13

def to_command

	tags = @data.map do |k, v|
		tag = k.to_s.capitalize
		next "<#{tag}>#{v}</#{tag}>"
	end

	return "<Command>#{tags.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