Class: ImageFormat

Inherits:
Object
  • Object
show all
Extended by:
SubclassTracking
Defined in:
lib/ImageFormat.rb

Constant Summary collapse

@@all_possible_extensions =
nil
@@code_for_tests =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SubclassTracking

extended

Constructor Details

#initialize(file_bytes) ⇒ ImageFormat

Returns a new instance of ImageFormat.



97
98
99
# File 'lib/ImageFormat.rb', line 97

def initialize(file_bytes)
  @file_bytes=file_bytes
end

Instance Attribute Details

#file_bytesObject

Returns the value of attribute file_bytes.



96
97
98
# File 'lib/ImageFormat.rb', line 96

def file_bytes
  @file_bytes
end

Class Method Details

.all_image_formatsObject



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

def self.all_image_formats
    ImageFormat.subclasses
end

.all_possible_extensionsObject



36
37
38
39
# File 'lib/ImageFormat.rb', line 36

def self.all_possible_extensions  
  @@all_possible_extensions= ImageFormat.all_image_formats.collect{|format| format.possible_extensions}.flatten.uniq.collect{|ext| ext.downcase} if @@all_possible_extensions.nil?
  @@all_possible_extensions
end

.code_for_testsObject



73
74
75
# File 'lib/ImageFormat.rb', line 73

def self.code_for_tests
  @@code_for_tests[self] || []
end

.host_systemObject



16
17
18
# File 'lib/ImageFormat.rb', line 16

def self.host_system
  nil
end

.is_valid_image_if(code_for_test) ⇒ Object



77
78
79
80
81
# File 'lib/ImageFormat.rb', line 77

def self.is_valid_image_if(code_for_test)
  RipXploreLog.debug  "adding test for #{self}: #{code_for_test.source}"
  @@code_for_tests[self] ||=[]
  @@code_for_tests[self]<<code_for_test.source
end

.possible_extensionsObject



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

def self.possible_extensions
    []
end

.possible_file_systemsObject



27
28
29
30
31
32
33
# File 'lib/ImageFormat.rb', line 27

def self.possible_file_systems
    results=[]
    FileSystem.all_file_systems.each do |candidate| 
      results<<candidate if (host_system==candidate.host_system) || (candidate.host_system==HostSystem)
    end
    results
end

Instance Method Details

#compatability_score(file_system_image) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ImageFormat.rb', line 83

def compatability_score(file_system_image)
  final_score=1
   self.class.code_for_tests.each do |code_for_test|
    RipXploreLog.debug "test for #{file_system_image.filename}#{self} : #{code_for_test} "
    result = eval code_for_test,binding
    RipXploreLog.debug "result : #{result}"     
    final_score+=1
    return 0  unless (result)
  end
  return final_score
end

#end_trackObject

what track does counting end at?



68
69
70
# File 'lib/ImageFormat.rb', line 68

def end_track
  track_count-1+start_track
end

#get_sector(track, sector) ⇒ Object

given a track number, a sector number, and an array of bytes, return an array of bytes representing the contents of that track/sector, or nil if specified track/sector not available needs to be overriden in each ImageFormat



53
54
55
# File 'lib/ImageFormat.rb', line 53

def get_sector(track,sector)
    nil 
end

#host_systemObject



20
21
22
# File 'lib/ImageFormat.rb', line 20

def host_system
  self.class.host_system
end

#sectors_in_track(track) ⇒ Object

given a track number, how many sectors should be in this track for this ImageFormat?



58
59
60
# File 'lib/ImageFormat.rb', line 58

def sectors_in_track(track)
   [0]
end

#start_trackObject

is the first track called track 0 or track 1?



64
65
66
# File 'lib/ImageFormat.rb', line 64

def start_track  
  host_system.respond_to?(:start_track) ? host_system.start_track : 0
end

#to_sObject



13
14
15
# File 'lib/ImageFormat.rb', line 13

def to_s
  self.class.name
end

#track_countObject

for a given byte stream, how many tracks could be interpreted by this image format?



47
48
49
# File 'lib/ImageFormat.rb', line 47

def track_count
  0  
end

#track_listObject

return an array containing a list of numbers of valid tracks on this image



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

def track_list
    (start_track..end_track).collect
end