lib/fontist/manifest/locations.rb in fontist-1.7.2 vs lib/fontist/manifest/locations.rb in fontist-1.7.3

- old
+ new

@@ -3,40 +3,40 @@ class Locations def initialize(manifest) @manifest = manifest end - def self.call(manifest) - new(manifest).call + def self.from_file(file, **keywords) + raise Fontist::Errors::ManifestCouldNotBeFoundError unless File.exist?(file) + + manifest = YAML.load_file(file) + raise Fontist::Errors::ManifestCouldNotBeReadError unless manifest.is_a?(Hash) + + from_hash(manifest, **keywords) end + def self.from_hash(manifest, **keywords) + if keywords.empty? + new(manifest).call + else + new(manifest, **keywords).call + end + end + def call font_names.zip(font_paths).to_h end private + attr_reader :manifest + def font_names - fonts.keys + manifest.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| + manifest.map do |font, styles| styles_to_ary = [styles].flatten style_paths_map(font, styles_to_ary) end end