class Fontist::Formula

Constants

NAMESPACES

Public Class Methods

all() click to toggle 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
all_keys() click to toggle 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
find(font_name) click to toggle source
# File lib/fontist/formula.rb, line 29
def self.find(font_name)
  Indexes::FontIndex.from_yaml.load_formulas(font_name).first
end
find_by_font_file(font_file) click to toggle 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
find_by_key(key) click to toggle 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
find_by_key_or_name(name) click to toggle 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
find_by_name(name) click to toggle source
# File lib/fontist/formula.rb, line 70
def self.find_by_name(name)
  key = name_to_key(name)

  find_by_key(key)
end
find_fonts(font_name) click to toggle 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
find_many(font_name) click to toggle source
# File lib/fontist/formula.rb, line 33
def self.find_many(font_name)
  Indexes::FontIndex.from_yaml.load_formulas(font_name)
end
find_styles(font_name, style_name) click to toggle 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
name_to_key(name) click to toggle source
# File lib/fontist/formula.rb, line 76
def self.name_to_key(name)
  name.downcase.gsub(" ", "_")
end
new(data, path) click to toggle source
# File lib/fontist/formula.rb, line 95
def initialize(data, path)
  @data = data
  @path = real_path(path)
end
new_from_file(path) click to toggle source
# File lib/fontist/formula.rb, line 90
def self.new_from_file(path)
  data = YAML.load_file(path)
  new(data, path)
end
update_formulas_repo() click to toggle source
# File lib/fontist/formula.rb, line 13
def self.update_formulas_repo
  Update.call
end

Public Instance Methods

description() click to toggle source
# File lib/fontist/formula.rb, line 132
def description
  @data["description"]
end
digest() click to toggle source
# File lib/fontist/formula.rb, line 198
def digest
  @data["digest"]
end
downloadable?() click to toggle source
# File lib/fontist/formula.rb, line 108
def downloadable?
  @data.key?("resources")
end
extract() click to toggle source
# File lib/fontist/formula.rb, line 164
def extract
  Helpers.parse_to_object(@data["extract"])
end
file_size() click to toggle source
# File lib/fontist/formula.rb, line 168
def file_size
  return unless @data["resources"]

  @data["resources"].values.first["file_size"]&.to_i
end
font_by_name(name) click to toggle source
# File lib/fontist/formula.rb, line 182
def font_by_name(name)
  fonts.find do |font|
    font.name.casecmp?(name)
  end
end
fonts() click to toggle source
# File lib/fontist/formula.rb, line 194
def fonts
  @fonts ||= Helpers.parse_to_object(fonts_by_family)
end
fonts_by_name(name) click to toggle source
# File lib/fontist/formula.rb, line 188
def fonts_by_name(name)
  fonts.select do |font|
    font.name.casecmp?(name)
  end
end
homepage() click to toggle source
# File lib/fontist/formula.rb, line 136
def homepage
  @data["homepage"]
end
instructions() click to toggle source
# File lib/fontist/formula.rb, line 178
def instructions
  @data["instructions"]
end
key() click to toggle source
# File lib/fontist/formula.rb, line 122
def key
  @key ||= {}
  @key[@path] ||= key_from_path
end
license() click to toggle source
# File lib/fontist/formula.rb, line 148
def license
  @data["open_license"] || @data["requires_license_agreement"]
end
license_required() click to toggle source
# File lib/fontist/formula.rb, line 152
def license_required
  @data["requires_license_agreement"] ? true : false
end
license_url() click to toggle source
# File lib/fontist/formula.rb, line 144
def license_url
  @data["license_url"]
end
manual?() click to toggle source
# File lib/fontist/formula.rb, line 104
def manual?
  !downloadable?
end
min_fontist() click to toggle source
# File lib/fontist/formula.rb, line 160
def min_fontist
  @data["min_fontist"]
end
name() click to toggle source
# File lib/fontist/formula.rb, line 127
def name
  @name ||= {}
  @name[key] ||= namespace.empty? ? base_name : "#{namespace}/#{base_name}"
end
path() click to toggle source
# File lib/fontist/formula.rb, line 118
def path
  @path
end
platforms() click to toggle source
# File lib/fontist/formula.rb, line 156
def platforms
  @data["platforms"]
end
resources() click to toggle source
# File lib/fontist/formula.rb, line 174
def resources
  Helpers.parse_to_object(@data["resources"]&.values)
end
source() click to toggle source
# File lib/fontist/formula.rb, line 112
def source
  return unless @data["resources"]

  @data["resources"].values.first["source"]
end
style_override(font) click to toggle source
# File lib/fontist/formula.rb, line 202
def style_override(font)
  fonts
    .map(&:styles)
    .flatten
    .detect { |s| s.family_name == font }
    &.dig(:override) || {}
end
to_index_formula() click to toggle source
# File lib/fontist/formula.rb, line 100
def to_index_formula
  Indexes::IndexFormula.new(path)
end