class Fontist::Formula

Public Class Methods

all() click to toggle source
# File lib/fontist/formula.rb, line 12
def self.all
  Dir[Fontist.formulas_path.join("**/*.yml").to_s].map do |path|
    Formula.new_from_file(path)
  end
end
find(font_name) click to toggle source
# File lib/fontist/formula.rb, line 18
def self.find(font_name)
  Indexes::FontIndex.from_yaml.load_formulas(font_name).first
end
find_fonts(font_name) click to toggle source
# File lib/fontist/formula.rb, line 26
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 22
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 36
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
new(data, path) click to toggle source
# File lib/fontist/formula.rb, line 53
def initialize(data, path)
  @data = data
  @path = path
end
new_from_file(path) click to toggle source
# File lib/fontist/formula.rb, line 48
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 8
def self.update_formulas_repo
  Update.call
end

Public Instance Methods

description() click to toggle source
# File lib/fontist/formula.rb, line 70
def description
  @data["description"]
end
digest() click to toggle source
# File lib/fontist/formula.rb, line 106
def digest
  @data["digest"]
end
extract() click to toggle source
# File lib/fontist/formula.rb, line 94
def extract
  Helpers.parse_to_object(@data["extract"])
end
fonts() click to toggle source
# File lib/fontist/formula.rb, line 102
def fonts
  @fonts ||= Helpers.parse_to_object(hash_collection_fonts + hash_fonts)
end
homepage() click to toggle source
# File lib/fontist/formula.rb, line 74
def homepage
  @data["homepage"]
end
key() click to toggle source
# File lib/fontist/formula.rb, line 66
def key
  @data["key"] || default_key
end
license() click to toggle source
# File lib/fontist/formula.rb, line 86
def license
  @data["open_license"] || @data["requires_license_agreement"]
end
license_required() click to toggle source
# File lib/fontist/formula.rb, line 90
def license_required
  @data["requires_license_agreement"] ? true : false
end
license_url() click to toggle source
# File lib/fontist/formula.rb, line 82
def license_url
  @data["license_url"]
end
path() click to toggle source
# File lib/fontist/formula.rb, line 62
def path
  @path
end
resources() click to toggle source
# File lib/fontist/formula.rb, line 98
def resources
  Helpers.parse_to_object(@data["resources"].values)
end
to_index_formula() click to toggle source
# File lib/fontist/formula.rb, line 58
def to_index_formula
  Indexes::IndexFormula.new(path)
end

Private Instance Methods

default_key() click to toggle source
# File lib/fontist/formula.rb, line 112
def default_key
  escaped = Regexp.escape(Fontist.formulas_path.to_s + "/")
  @path.sub(Regexp.new("^" + escaped), "").sub(/\.yml$/, "")
end
hash_collection_fonts() click to toggle source
# File lib/fontist/formula.rb, line 117
def hash_collection_fonts
  return [] unless @data["font_collections"]

  @data["font_collections"].flat_map do |coll|
    filenames = { "font" => coll["filename"],
                  "source_font" => coll["source_filename"] }

    coll["fonts"].map do |font|
      { "name" => font["name"],
        "styles" => font["styles"].map { |s| filenames.merge(s) } }
    end
  end
end
hash_fonts() click to toggle source
# File lib/fontist/formula.rb, line 131
def hash_fonts
  return [] unless @data["fonts"]

  @data["fonts"]
end