Class: HexFile::Info
- Inherits:
-
Object
- Object
- HexFile::Info
- Defined in:
- lib/hex_file/info.rb
Instance Method Summary collapse
- #binary_size ⇒ Object
- #find_record(regex) ⇒ Object
- #format ⇒ Object
-
#initialize(input_stream) ⇒ Info
constructor
A new instance of Info.
- #linear_record_types?(record_types) ⇒ Boolean
- #record_types ⇒ Object
- #records ⇒ Object
- #serialize ⇒ Object
- #start_segment_record_type?(record_types) ⇒ Boolean
Constructor Details
Instance Method Details
#binary_size ⇒ Object
22 23 24 |
# File 'lib/hex_file/info.rb', line 22 def binary_size records.map { |r| r.data_size }.reduce(:+) end |
#find_record(regex) ⇒ Object
13 14 15 16 |
# File 'lib/hex_file/info.rb', line 13 def find_record regex regex = Regexp.new(regex, 'i') unless regex.is_a?(Regexp) records.find { |rec| rec.data =~ regex } end |
#format ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/hex_file/info.rb', line 26 def format if linear_record_types?(record_types) 'I32HEX' elsif start_segment_record_type?(record_types) 'I16HEX' else 'I8HEX' end end |
#linear_record_types?(record_types) ⇒ Boolean
40 41 42 43 |
# File 'lib/hex_file/info.rb', line 40 def linear_record_types?(record_types) record_types.include?(Record::EXTENDED_LINEAR_ADDRESS) || record_types.include?(Record::START_LINEAR_ADDRESS) end |
#record_types ⇒ Object
36 37 38 |
# File 'lib/hex_file/info.rb', line 36 def record_types @record_types ||= records.map { |r| r.type }.uniq end |
#records ⇒ Object
9 10 11 |
# File 'lib/hex_file/info.rb', line 9 def records @records.each end |
#serialize ⇒ Object
18 19 20 |
# File 'lib/hex_file/info.rb', line 18 def serialize records.map(&:raw).join("\n") end |
#start_segment_record_type?(record_types) ⇒ Boolean
45 46 47 |
# File 'lib/hex_file/info.rb', line 45 def start_segment_record_type?(record_types) record_types.include?(Record::START_SEGMENT_ADDRESS) end |