Class: DOSFile

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

Overview

Apple DOS 3.3 file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, locked, sector_count, contents, file_type = nil) ⇒ DOSFile

Returns a new instance of DOSFile.



10
11
12
13
14
15
16
# File 'lib/DOSFile.rb', line 10

def initialize(filename,locked,sector_count,contents,file_type=nil)
	@filename=filename
	@locked=locked
	@sector_count=sector_count
	@file_type= file_type
	@contents=contents
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



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

def contents
  @contents
end

#file_typeObject

File type as displayed in Apple DOS 3.3 Catalog



19
20
21
# File 'lib/DOSFile.rb', line 19

def file_type
  @file_type
end

#filenameObject

Returns the value of attribute filename.



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

def filename
  @filename
end

#lockedObject

Returns the value of attribute locked.



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

def locked
  @locked
end

#sector_countObject

Returns the value of attribute sector_count.



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

def sector_count
  @sector_count
end

Instance Method Details

#hex_dumpObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/DOSFile.rb', line 27

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



23
24
25
# File 'lib/DOSFile.rb', line 23

def to_s
	@contents
end