Sha256: b2c75cb1f619feb4d9cd767b83072bbda88a3da915d73e6b6025bd9ff2dc0ed5

Contents?: true

Size: 901 Bytes

Versions: 11

Compression:

Stored size: 901 Bytes

Contents

module Fontist
  class FormulaPaths
    attr_reader :font_paths

    def initialize(font_paths)
      @font_paths = font_paths
    end

    def find(font, style = nil)
      styles = find_styles_by_formulas(font, style)
      return if styles.empty?

      fonts = styles.uniq { |s| s["font"] }.flat_map do |s|
        paths = search_font_paths(s["font"])
        paths.map do |path|
          { full_name: s["full_name"],
            path: path }
        end
      end

      fonts.empty? ? nil : fonts
    end

    private

    def find_styles_by_formulas(font, style)
      if style
        Formula.find_styles(font, style)
      else
        fonts = Formula.find_fonts(font)
        return [] unless fonts

        fonts.flat_map(&:styles)
      end
    end

    def search_font_paths(filename)
      font_paths.select do |path|
        File.basename(path) == filename
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fontist-1.8.11 lib/fontist/formula_paths.rb
fontist-1.8.10 lib/fontist/formula_paths.rb
fontist-1.8.9 lib/fontist/formula_paths.rb
fontist-1.8.8 lib/fontist/formula_paths.rb
fontist-1.8.7 lib/fontist/formula_paths.rb
fontist-1.8.6 lib/fontist/formula_paths.rb
fontist-1.8.5 lib/fontist/formula_paths.rb
fontist-1.8.4 lib/fontist/formula_paths.rb
fontist-1.8.3 lib/fontist/formula_paths.rb
fontist-1.8.2 lib/fontist/formula_paths.rb
fontist-1.8.1 lib/fontist/formula_paths.rb