Class: NADOLFile
- Inherits:
-
Object
- Object
- NADOLFile
- Defined in:
- lib/NADOLFile.rb
Overview
NADOL (Nibbles Away Disk Optimized Language) file
Direct Known Subclasses
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
- #file_extension ⇒ Object
- #hex_dump ⇒ Object
-
#initialize(filename, contents) ⇒ NADOLFile
constructor
A new instance of NADOLFile.
- #to_s ⇒ Object
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
#contents ⇒ Object
Returns the value of attribute contents.
8 9 10 |
# File 'lib/NADOLFile.rb', line 8 def contents @contents end |
#filename ⇒ Object
Returns the value of attribute filename.
8 9 10 |
# File 'lib/NADOLFile.rb', line 8 def filename @filename end |
Instance Method Details
#file_extension ⇒ Object
18 19 20 |
# File 'lib/NADOLFile.rb', line 18 def file_extension ".bin" end |
#hex_dump ⇒ Object
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_s ⇒ Object
14 15 16 |
# File 'lib/NADOLFile.rb', line 14 def to_s @contents end |