Class: NativeFileType
Direct Known Subclasses
AcornBASIC, AcornBinary, AcornText, AppleBinary, AppleHiResPic, AppleText, AppleWorksWP, Applesoft, AtariBasic, AtariBinary, AtariBitmapFont, AtariMicroPainterPic, AtariText, CPMFile, CbmFile, CocoBasic, CocoMachineLanguage, CocoText, GenericFile, IntegerBASIC, NADOLFile, PascalFile, ProDosFile, Ti99File, Trs80BasicListing, Trs80Cmd, Trs80Jcl, Trs80LevelIIBasic, Trs80PascalSource, Trs80Text, Zx81Basic
Constant Summary
collapse
- @@code_for_tests =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.all_native_file_types ⇒ Object
-
.best_fit(file_system_image, filename, contents, file_type = nil, aux_code = nil) ⇒ Object
given metadata and contents of a file from a file system image, return an instance of the NativeFileType subclass that is the closest match.
-
.code_for_tests ⇒ Object
-
.compatability_score(file_system_image, filename, contents, file_type, aux_code) ⇒ Object
-
.file_type_matches?(file_system_image, file_type) ⇒ Boolean
-
.is_valid_file_if(code_for_test) ⇒ Object
-
.load_address(filebytes) ⇒ Object
-
.matching_score ⇒ Object
-
.native_file_types_possible_on_file_system(file_system) ⇒ Object
-
.non_matching_score ⇒ Object
Instance Method Summary
collapse
extended
Constructor Details
#initialize(file_system_image, filename, contents, file_type, aux_code) ⇒ NativeFileType
Returns a new instance of NativeFileType.
10
11
12
13
14
15
16
17
|
# File 'lib/NativeFileType.rb', line 10
def initialize(file_system_image,filename,contents,file_type,aux_code)
@file_system_image=file_system_image
@filename=filename
@contents=contents
@file_type=file_type
@aux_code=aux_code
@meta_data={}
end
|
Instance Attribute Details
#aux_code ⇒ Object
Returns the value of attribute aux_code.
9
10
11
|
# File 'lib/NativeFileType.rb', line 9
def aux_code
@aux_code
end
|
#contents ⇒ Object
Returns the value of attribute contents.
9
10
11
|
# File 'lib/NativeFileType.rb', line 9
def contents
@contents
end
|
#file_system_image ⇒ Object
Returns the value of attribute file_system_image.
9
10
11
|
# File 'lib/NativeFileType.rb', line 9
def file_system_image
@file_system_image
end
|
#file_type ⇒ Object
Returns the value of attribute file_type.
9
10
11
|
# File 'lib/NativeFileType.rb', line 9
def file_type
@file_type
end
|
#filename ⇒ Object
Returns the value of attribute filename.
9
10
11
|
# File 'lib/NativeFileType.rb', line 9
def filename
@filename
end
|
Returns the value of attribute meta_data.
9
10
11
|
# File 'lib/NativeFileType.rb', line 9
def meta_data
@meta_data
end
|
Class Method Details
.all_native_file_types ⇒ Object
.best_fit(file_system_image, filename, contents, file_type = nil, aux_code = nil) ⇒ Object
given metadata and contents of a file from a file system image, return an instance of the NativeFileType subclass that is the closest match
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/NativeFileType.rb', line 94
def NativeFileType.best_fit(file_system_image,filename,contents,file_type=nil,aux_code=nil)
candidates={}
NativeFileType.all_native_file_types.each do |native_file_type|
if !native_file_type.file_system_file_types.keys.include?(file_system_image.file_system) then
RipXploreLog.debug("skipping #{native_file_type} - can't reside on #{file_system_image.file_system}")
else
RipXploreLog.debug("checking native file type #{native_file_type}")
candidate_score=native_file_type.compatability_score(file_system_image,filename,contents,file_type,aux_code)
RipXploreLog.debug("score - #{candidate_score}")
candidates[native_file_type]=candidate_score
end
end
if candidates.length==0 then
RipXploreLog.debug( 'no valid combination of file system and native file types found')
return nil
end
best_candidate=candidates.keys.sort{|a,b| candidates[b]<=>candidates[a]}[0]
RipXploreLog.debug("best candidate for #{filename} = #{best_candidate} score: #{candidates[best_candidate]}")
native_file=best_candidate.new(file_system_image,filename,contents,file_type,aux_code)
if GenericGIF.is_gif?(native_file) then
RipXploreLog.debug(" #{filename} is a GIF")
native_file.extend GenericGIF
end
if native_file.respond_to?(:files) then
return [native_file,native_file.files].flatten
else
return native_file
end
end
|
.code_for_tests ⇒ Object
147
148
149
|
# File 'lib/NativeFileType.rb', line 147
def self.code_for_tests
@@code_for_tests[self] || []
end
|
.compatability_score(file_system_image, filename, contents, file_type, aux_code) ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/NativeFileType.rb', line 157
def self.compatability_score(file_system_image,filename,contents,file_type,aux_code)
return non_matching_score unless (file_type_matches?(file_system_image,file_type))
load_address=self.load_address(contents)
passed_tests=0
code_for_tests.each do |code_for_test|
RipXploreLog.debug "test for #{self} : #{code_for_test}"
result = eval code_for_test,binding
RipXploreLog.debug "RESULT: #{result}"
return non_matching_score unless (result)
passed_tests+=1
end
return matching_score+passed_tests
end
|
.file_type_matches?(file_system_image, file_type) ⇒ Boolean
127
128
129
130
131
132
133
134
135
|
# File 'lib/NativeFileType.rb', line 127
def NativeFileType.file_type_matches?(file_system_image,file_type)
result=false
[file_system_file_types[file_system_image.file_system]].flatten.each do |target_file_type|
result=true if target_file_type==:any
result=true if(file_type.to_s==target_file_type.to_s)
RipXploreLog.debug "test for #{file_type} == #{target_file_type} : #{result}"
end
result
end
|
.is_valid_file_if(code_for_test) ⇒ Object
151
152
153
154
155
|
# File 'lib/NativeFileType.rb', line 151
def self.is_valid_file_if(code_for_test)
@@code_for_tests[self] ||=[]
@@code_for_tests[self]<<code_for_test.source
end
|
.load_address(filebytes) ⇒ Object
50
51
52
|
# File 'lib/NativeFileType.rb', line 50
def NativeFileType.load_address(filebytes)
0
end
|
.matching_score ⇒ Object
19
20
21
|
# File 'lib/NativeFileType.rb', line 19
def NativeFileType.matching_score
ancestors.length
end
|
.native_file_types_possible_on_file_system(file_system) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/NativeFileType.rb', line 32
def NativeFileType.native_file_types_possible_on_file_system(file_system)
candidates=[]
NativeFileType.all_native_file_types.each do |native_file_type|
candidates<<native_file_type if (native_file_type.file_system_file_types.keys.include?(file_system) ) && (native_file_type.file_system_file_types[file_system]!=:any)
end
candidates.sort {|a,b| a.to_s <=> b.to_s}
end
|
.non_matching_score ⇒ Object
23
24
25
|
# File 'lib/NativeFileType.rb', line 23
def NativeFileType.non_matching_score
0
end
|
Instance Method Details
#<=>(o) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/NativeFileType.rb', line 54
def <=>(o)
return -1 unless o.respond_to?(:filename)
if filename==o.filename then
return self.to_s<=>o.to_s
else
return (filename<=>o.filename)
end
end
|
#==(other_object) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/NativeFileType.rb', line 82
def ==(other_object)
if !other_object.kind_of? NativeFileType then
return false
end
if self.filename!=other_object.filename then
return false
end
return self.to_s==other_object.to_s
end
|
142
143
144
|
# File 'lib/NativeFileType.rb', line 142
def
(@contents.length>) ? @contents[,@contents.length-] : ""
end
|
#full_filename ⇒ Object
some filesystems differentiate between full and partial filenames. e.g. in ProDOS the ‘full’ filename includes the full path by default, full_filename is the same as filename, but can be overridden for those filesystems that need this
78
79
80
|
# File 'lib/NativeFileType.rb', line 78
def full_filename
@filename
end
|
how many bytes should be skipped to get to the file data?
138
139
140
|
# File 'lib/NativeFileType.rb', line 138
def
0
end
|
#load_address ⇒ Object
45
46
47
|
# File 'lib/NativeFileType.rb', line 45
def load_address
self.class.load_address(contents)
end
|
#to_hex_dump ⇒ Object
63
64
65
|
# File 'lib/NativeFileType.rb', line 63
def to_hex_dump
file_system_image.file_system.host_system.hex_dump(contents)
end
|
#to_info_dump ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/NativeFileType.rb', line 67
def to_info_dump
s="class: #{self.class}\n"
s+="filename: #{self.filename}\n"
@meta_data.keys.sort.each {|k| s<<"#{k}: #{@meta_data[k]}\n"}
s
end
|
#type_description ⇒ Object
how should this file be described in a catalog list?
41
42
43
|
# File 'lib/NativeFileType.rb', line 41
def type_description
self.class
end
|