Class: CPMFile

Inherits:
DSKFile show all
Defined in:
lib/CPMFile.rb

Direct Known Subclasses

MBASICFile

Constant Summary

Constants inherited from DSKFile

DSKFile::APPLESOFT_TOKENS

Instance Attribute Summary collapse

Attributes inherited from DSKFile

#contents, #filename

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DSKFile

#==, #buffer_as_applesoft_file, #hex_dump, #length_in_sectors, #to_ascii

Constructor Details

#initialize(filename, contents) ⇒ CPMFile

Returns a new instance of CPMFile.



16
17
18
19
20
# File 'lib/CPMFile.rb', line 16

def initialize(filename,contents)    
	@filename,@file_type=CPMFile.split_filename(filename)
   raise "invalid filename #{filename}" if @filename.nil?
	@contents=contents    
end

Instance Attribute Details

#file_typeObject

Returns the value of attribute file_type.



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

def file_type
  @file_type
end

Class Method Details

.split_filename(filename) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/CPMFile.rb', line 9

def CPMFile.split_filename(filename)
  filename=~/^([^.]{0,8})(\.([^.]{0,3}))?$/ #filename should have 0-8 chars, then optionally a dot and up to 3 more chars.		
  partial_filename=$1
  ext=$3
  ext="" if ext.nil?
return [partial_filename,ext]
end

Instance Method Details

#can_be_picture?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/CPMFile.rb', line 38

def can_be_picture?		
	file_type==:foto && HGR.can_be_hgr_screen?(@contents)
end

#file_extensionObject



34
35
36
# File 'lib/CPMFile.rb', line 34

def file_extension
	return "."+@file_type.downcase
end

#full_filenameObject



22
23
24
25
26
27
28
# File 'lib/CPMFile.rb', line 22

def full_filename
  if @file_type=="" then
    @filename
  else      
    "#{@filename}.#{@file_type}"
  end
end

#to_png(pallete_mode = :amber) ⇒ Object



42
43
44
# File 'lib/CPMFile.rb', line 42

def to_png(pallete_mode=:amber)
	HGR.buffer_to_png(@contents,pallete_mode)
end

#to_sObject



30
31
32
# File 'lib/CPMFile.rb', line 30

def to_s
   @contents.gsub(/\x1A*$/,'')
end