Class: NADOLFile

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

Overview

NADOL (Nibbles Away Disk Optimized Language) file

Direct Known Subclasses

NADOLBinaryFile, NADOLTokenisedFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, contents) ⇒ NADOLFile

Returns a new instance of NADOLFile.



9
10
11
12
# File 'lib/NADOLFile.rb', line 9

def initialize(filename,contents)
	@filename=filename
	@contents=contents
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



8
9
10
# File 'lib/NADOLFile.rb', line 8

def contents
  @contents
end

#filenameObject

Returns the value of attribute filename.



8
9
10
# File 'lib/NADOLFile.rb', line 8

def filename
  @filename
end

Instance Method Details

#file_extensionObject



18
19
20
# File 'lib/NADOLFile.rb', line 18

def file_extension
	".bin"
end

#hex_dumpObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/NADOLFile.rb', line 21

def hex_dump
	#assumes file is a multiple of 16 bytes, which it always should be
	s=""
	(0..(@contents.length/16)-1).each {|line_number|
		 lhs=""
		 rhs=""
		 start_byte=line_number*16
		 line=@contents[start_byte..start_byte+15]
		 line.each_byte {|byte|
			  lhs+= sprintf("%02X ", byte)
			  rhs+= (byte%128).chr.sub(/[\x00-\x1f]/,'.')
	 	}
		s+=sprintf("%02X\t%s %s\n",start_byte,lhs,rhs)
	}
	s
end

#to_sObject



14
15
16
# File 'lib/NADOLFile.rb', line 14

def to_s
	@contents
end