class Fontist::Formula
Constants
- NAMESPACES
Public Class Methods
Source
# File lib/fontist/formula.rb, line 17 def self.all Dir[Fontist.formulas_path.join("**/*.yml").to_s].map do |path| Formula.new_from_file(path) end end
Source
# File lib/fontist/formula.rb, line 23 def self.all_keys Dir[Fontist.formulas_path.join("**/*.yml").to_s].map do |path| path.sub("#{Fontist.formulas_path}/", "").sub(".yml", "") end end
Source
# File lib/fontist/formula.rb, line 29 def self.find(font_name) Indexes::FontIndex.from_yaml.load_formulas(font_name).first end
Source
# File lib/fontist/formula.rb, line 80 def self.find_by_font_file(font_file) key = Indexes::FilenameIndex .from_yaml .load_index_formulas(File.basename(font_file)) .map(&:name) .first find_by_key(key) end
Source
# File lib/fontist/formula.rb, line 63 def self.find_by_key(key) path = Fontist.formulas_path.join("#{key}.yml") return unless File.exist?(path) new_from_file(path) end
Source
# File lib/fontist/formula.rb, line 59 def self.find_by_key_or_name(name) find_by_key(name) || find_by_name(name) end
Source
# File lib/fontist/formula.rb, line 70 def self.find_by_name(name) key = name_to_key(name) find_by_key(key) end
Source
# File lib/fontist/formula.rb, line 37 def self.find_fonts(font_name) formulas = Indexes::FontIndex.from_yaml.load_formulas(font_name) formulas.map do |formula| formula.fonts.select do |f| f.name.casecmp?(font_name) end end.flatten end
Source
# File lib/fontist/formula.rb, line 33 def self.find_many(font_name) Indexes::FontIndex.from_yaml.load_formulas(font_name) end
Source
# File lib/fontist/formula.rb, line 47 def self.find_styles(font_name, style_name) formulas = Indexes::FontIndex.from_yaml.load_formulas(font_name) formulas.map do |formula| formula.fonts.map do |f| f.styles.select do |s| f.name.casecmp?(font_name) && s.type.casecmp?(style_name) end end end.flatten end
Source
# File lib/fontist/formula.rb, line 76 def self.name_to_key(name) name.downcase.gsub(" ", "_") end
Source
# File lib/fontist/formula.rb, line 98 def initialize(data, path) @data = data @path = real_path(path) end
Source
# File lib/fontist/formula.rb, line 90 def self.new_from_file(path) data = YAML.safe_load( File.read(path), permitted_classes: [Date, Symbol, Time] ) new(data, path) end
Source
# File lib/fontist/formula.rb, line 13 def self.update_formulas_repo Update.call end
Public Instance Methods
Source
# File lib/fontist/formula.rb, line 135 def description @data["description"] end
Source
# File lib/fontist/formula.rb, line 111 def downloadable? @data.key?("resources") end
Source
# File lib/fontist/formula.rb, line 167 def extract Helpers.parse_to_object(@data["extract"]) end
Source
# File lib/fontist/formula.rb, line 171 def file_size return unless @data["resources"] @data["resources"].values.first["file_size"]&.to_i end
Source
# File lib/fontist/formula.rb, line 185 def font_by_name(name) fonts.find do |font| font.name.casecmp?(name) end end
Source
# File lib/fontist/formula.rb, line 197 def fonts @fonts ||= Helpers.parse_to_object(fonts_by_family) end
Source
# File lib/fontist/formula.rb, line 191 def fonts_by_name(name) fonts.select do |font| font.name.casecmp?(name) end end
Source
# File lib/fontist/formula.rb, line 181 def instructions @data["instructions"] end
Source
# File lib/fontist/formula.rb, line 125 def key @key ||= {} @key[@path] ||= key_from_path end
Source
# File lib/fontist/formula.rb, line 151 def license @data["open_license"] || @data["requires_license_agreement"] end
Source
# File lib/fontist/formula.rb, line 155 def license_required @data["requires_license_agreement"] ? true : false end
Source
# File lib/fontist/formula.rb, line 147 def license_url @data["license_url"] end
Source
# File lib/fontist/formula.rb, line 163 def min_fontist @data["min_fontist"] end
Source
# File lib/fontist/formula.rb, line 130 def name @name ||= {} @name[key] ||= namespace.empty? ? base_name : "#{namespace}/#{base_name}" end
Source
# File lib/fontist/formula.rb, line 177 def resources Helpers.parse_to_object(@data["resources"]&.values) end
Source
# File lib/fontist/formula.rb, line 115 def source return unless @data["resources"] @data["resources"].values.first["source"] end
Source
# File lib/fontist/formula.rb, line 205 def style_override(font) fonts .map(&:styles) .flatten .detect { |s| s.family_name == font } &.dig(:override) || {} end
Source
# File lib/fontist/formula.rb, line 103 def to_index_formula Indexes::IndexFormula.new(path) end