class Fontist::Manifest::Locations
Attributes
manifest[R]
Public Class Methods
from_file(file, **keywords)
click to toggle source
# File lib/fontist/manifest/locations.rb, line 8 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
from_hash(manifest, **keywords)
click to toggle source
# File lib/fontist/manifest/locations.rb, line 17 def self.from_hash(manifest, **keywords) if keywords.empty? new(manifest).call else new(manifest, **keywords).call end end
new(manifest)
click to toggle source
# File lib/fontist/manifest/locations.rb, line 4 def initialize(manifest) @manifest = manifest end
Public Instance Methods
call()
click to toggle source
# File lib/fontist/manifest/locations.rb, line 25 def call font_names.zip(font_paths).to_h end
Private Instance Methods
empty_paths(style)
click to toggle source
# File lib/fontist/manifest/locations.rb, line 77 def empty_paths(style) [{ "full_name" => nil, "type" => style, "path" => nil }] end
file_paths(font, style)
click to toggle source
# File lib/fontist/manifest/locations.rb, line 65 def file_paths(font, style) find_font_with_name(font, style).tap do |x| if x.nil? raise Errors::MissingFontError.new(font, style) end end end
find_font_with_name(font, style)
click to toggle source
# File lib/fontist/manifest/locations.rb, line 73 def find_font_with_name(font, style) Fontist::SystemFont.find_styles(font, style) end
font_names()
click to toggle source
# File lib/fontist/manifest/locations.rb, line 33 def font_names manifest.keys end
font_paths()
click to toggle source
# File lib/fontist/manifest/locations.rb, line 37 def font_paths manifest.map do |font, styles| styles_to_ary = [styles].flatten style_paths_map(font, styles_to_ary) end end
group_paths(styles)
click to toggle source
# File lib/fontist/manifest/locations.rb, line 55 def group_paths(styles) styles.group_by { |s| s[:type] } .transform_values { |group| style(group) } end
style(styles)
click to toggle source
# File lib/fontist/manifest/locations.rb, line 60 def style(styles) { "full_name" => styles.first[:full_name], "paths" => styles.map { |x| x[:path] } }.compact end
style_paths(font, names)
click to toggle source
# File lib/fontist/manifest/locations.rb, line 49 def style_paths(font, names) names.flat_map do |style| file_paths(font, style) || empty_paths(style) end end
style_paths_map(font, names)
click to toggle source
# File lib/fontist/manifest/locations.rb, line 44 def style_paths_map(font, names) styles = style_paths(font, names) group_paths(styles) end