Sha256: 5031634221d565ad3e9d267731c137686881cfa56f738947936952abfdfe08d8

Contents?: true

Size: 796 Bytes

Versions: 6

Compression:

Stored size: 796 Bytes

Contents

require "ttfunk"

module Fontist
  class CollectionFile
    include Enumerable

    class << self
      def from_path(path)
        io = ::File.new(path, "rb")

        yield new(build_collection(io))
      ensure
        io.close
      end

      private

      def build_collection(io)
        TTFunk::Collection.new(io)
      rescue StandardError => e
        raise Errors::FontFileError,
              "Font file could not be parsed: #{e.inspect}."
      end
    end

    def initialize(ttfunk_collection)
      @collection = ttfunk_collection
    end

    def count
      @collection.count
    end

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

      self
    end

    def [](index)
      FontFile.from_collection_index(@collection, index)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fontist-1.21.2 lib/fontist/collection_file.rb
fontist-1.21.1 lib/fontist/collection_file.rb
fontist-1.20.0 lib/fontist/collection_file.rb
fontist-1.19.0 lib/fontist/collection_file.rb
fontist-1.18.2 lib/fontist/collection_file.rb
fontist-1.17.1 lib/fontist/collection_file.rb