Sha256: b9f19213d6ea779ba5cf30c7791a30db8e8b760068a28022fb16bc25d47c3e5d

Contents?: true

Size: 729 Bytes

Versions: 3

Compression:

Stored size: 729 Bytes

Contents

module TTFunk
  class Collection
    include Enumerable

    def self.open(path)
      ::File.open(path, 'rb') do |io|
        yield new(io)
      end
    end

    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

    def count
      @offsets.length
    end

    def each
      count.times do |index|
        yield self[index]
      end
      self
    end

    def [](index)
      @cache[index] ||= TTFunk::File.new(@contents, @offsets[index])
    end
  end
end

Version data entries

3 entries across 2 versions & 2 rubygems

Version Path
embulk-input-druginfo_interview_form-0.1.0 vendor/bundle/ruby/2.4.0/gems/ttfunk-1.5.1/lib/ttfunk/collection.rb
embulk-input-druginfo_interview_form-0.1.0 vendor/bundle/ruby/2.5.0/gems/ttfunk-1.5.1/lib/ttfunk/collection.rb
ttfunk-1.5.1 lib/ttfunk/collection.rb