Sha256: eef0eaeb824a89501cea25afe5f222443168381a1f0eb83c7d6537c1da9bb0bf

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

module Fontist
  module Manifest
    class Common
      def initialize(manifest)
        @manifest = manifest
      end

      def self.call(manifest)
        new(manifest).call
      end

      def call
        font_names.zip(font_paths).to_h
      end

      private

      def font_names
        fonts.keys
      end

      def fonts
        @fonts ||= begin
          unless File.exist?(@manifest)
            raise Fontist::Errors::ManifestCouldNotBeFoundError
          end

          fonts = YAML.load_file(@manifest)
          unless fonts.is_a?(Hash)
            raise Fontist::Errors::ManifestCouldNotBeReadError
          end

          fonts
        end
      end

      def font_paths
        fonts.map do |font, styles|
          styles_to_ary = [styles].flatten
          style_paths_map(font, styles_to_ary)
        end
      end

      def style_paths_map(font, names)
        paths = style_paths(font, names)
        names.zip(paths).to_h
      end

      def style_paths(font, names)
        names.map do |style|
          file_paths(font, style)
        end
      end

      def file_paths(_font, _style)
        raise NotImplementedError.new("Implement #file_paths in child class")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fontist-1.6.0 lib/fontist/manifest/common.rb
fontist-1.5.1 lib/fontist/manifest/common.rb
fontist-1.5.0 lib/fontist/manifest/common.rb