Sha256: ea13cb396d7ecf1b583b0cbf0b08ef3830f15b756507a9d9a74b695296ee2d71
Contents?: true
Size: 930 Bytes
Versions: 9
Compression:
Stored size: 930 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"], type: s["type"], 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
9 entries across 9 versions & 1 rubygems