Class: BytecodeConverter

Inherits:
Object show all
Includes:
HelperMethods
Defined in:
lib/swxruby/bytecode_converter.rb

Constant Summary collapse

NULL_TERMINATOR =
'00'

Class Method Summary collapse

Methods included from HelperMethods

included

Methods included from HelperMethods::ClassMethods

#calculate_bytecode_length, #generate_push_statement, #integer_to_hexadecimal, #make_little_endian, #pad_string_to_byte_boundary, #string_length_in_bytes_hex

Class Method Details

.convert(data) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/swxruby/bytecode_converter.rb', line 10

def convert(data)
  conversion_method = "#{data.class.to_s.downcase}_to_bytecode"
  
  if respond_to?(conversion_method)
    send(conversion_method, data)
  else
	# Convert the object to a hash of its instance variables 
	object_hash = data.instance_values
	
	if object_hash.empty?
		raise StandardError, "#{data.class} is an unhandled data type."
	else
     hash_to_bytecode(object_hash)
	end
  end
end