Class: Fontisan::Binary::BaseRecord

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/fontisan/binary/base_record.rb

Overview

Base class for all BinData record definitions

Provides common configuration for OpenType binary structures:

  • Big-endian byte order (OpenType standard)

  • Common helper methods

All table parsers and binary structures should inherit from this class to ensure consistent behavior across the codebase.

Examples:

Defining a simple structure

class MyTable < Binary::BaseRecord
  uint16 :version
  uint16 :count
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.read(io) ⇒ Object

Override read to handle nil data gracefully



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fontisan/binary/base_record.rb', line 26

def self.read(io)
  return new if io.nil? || (io.respond_to?(:empty?) && io.empty?)

  # Store the original data for later parsing
  # Convert IO to string if needed
  if io.is_a?(String)
    data = io
    instance = super(StringIO.new(data))
  else
    # For IO objects, read to string first
    data = io.read
    io.rewind if io.respond_to?(:rewind)
    instance = super(io)
  end

  instance.instance_variable_set(:@raw_data, data)
  instance
end

Instance Method Details

#raw_dataString

Get the raw binary data that was read

Returns:

  • (String)

    Raw binary data



48
49
50
# File 'lib/fontisan/binary/base_record.rb', line 48

def raw_data
  @raw_data || to_binary_s
end

#valid?Boolean

Check if the record is valid

Returns:

  • (Boolean)

    True if valid, false otherwise



55
56
57
# File 'lib/fontisan/binary/base_record.rb', line 55

def valid?
  true
end