class TTFunk::Collection

Public Class Methods

new(io) click to toggle source
# File lib/ttfunk/collection.rb, line 11
def initialize(io)
  tag = io.read(4)
  raise ArgumentError, 'not a TTC file' unless tag == 'ttcf'

  _major, _minor = io.read(4).unpack('n*')
  count = io.read(4).unpack('N').first
  @offsets = io.read(count * 4).unpack('N*')

  io.rewind
  @contents = io.read
  @cache = []
end
open(path) { |new(io)| ... } click to toggle source
# File lib/ttfunk/collection.rb, line 5
def self.open(path)
  ::File.open(path, 'rb') do |io|
    yield new(io)
  end
end

Public Instance Methods

[](index) click to toggle source
# File lib/ttfunk/collection.rb, line 35
def [](index)
  @cache[index] ||= TTFunk::File.new(@contents, @offsets[index])
end
count() click to toggle source
# File lib/ttfunk/collection.rb, line 24
def count
  @offsets.length
end
each() { |self| ... } click to toggle source
# File lib/ttfunk/collection.rb, line 28
def each
  count.times do |index|
    yield self[index]
  end
  self
end