lib/fontist/manifest/locations.rb in fontist-1.6.0 vs lib/fontist/manifest/locations.rb in fontist-1.7.0

- old
+ new

@@ -1,13 +1,60 @@ -require_relative "common" - module Fontist module Manifest - class Locations < Common + class Locations + 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) - Fontist::SystemFont.find_with_style(font, style) + Fontist::SystemFont.find_with_style(font, style).transform_keys(&:to_s) end end end end