Class: S19::MotFile

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records = []) ⇒ MotFile

Returns a new instance of MotFile.



134
135
136
# File 'lib/rsrec.rb', line 134

def initialize records=[]
  @records=records
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



133
134
135
# File 'lib/rsrec.rb', line 133

def records
  @records
end

Class Method Details

.from_file(filename) ⇒ Object

Parses a .mot file in memory, returns MotFile



149
150
151
152
# File 'lib/rsrec.rb', line 149

def self.from_file filename
  records=File.readlines(filename).map{|line| SRecord.parse(line)}
  MotFile.new(records)
end

Instance Method Details

#data_recordsObject

Just the data records



141
142
143
# File 'lib/rsrec.rb', line 141

def data_records
  @records.select{|rec| rec.data_record?}.compact
end

#image_sizeObject

The total size of the image in bytes



145
146
147
# File 'lib/rsrec.rb', line 145

def image_size
  data_records.last.address+data_records.last.binary.size-data_records.first.address
end

#to_sObject



137
138
139
# File 'lib/rsrec.rb', line 137

def to_s
  @records.each_with_object(""){|record,msg| msg<<"#{record}\n"}
end