Class: Fontist::Formula
- Inherits:
-
Object
- Object
- Fontist::Formula
- Defined in:
- lib/fontist/formula.rb
Class Method Summary collapse
- .all ⇒ Object
- .find(font_name) ⇒ Object
- .find_fonts(font_name) ⇒ Object
- .find_many(font_name) ⇒ Object
- .find_styles(font_name, style_name) ⇒ Object
- .new_from_file(path) ⇒ Object
- .update_formulas_repo ⇒ Object
Instance Method Summary collapse
- #copyright ⇒ Object
- #description ⇒ Object
- #digest ⇒ Object
- #downloadable? ⇒ Boolean
- #extract ⇒ Object
- #file_size ⇒ Object
- #fonts ⇒ Object
- #fonts_by_name(name) ⇒ Object
- #homepage ⇒ Object
-
#initialize(data, path) ⇒ Formula
constructor
A new instance of Formula.
- #instructions ⇒ Object
- #key ⇒ Object
- #license ⇒ Object
- #license_required ⇒ Object
- #license_url ⇒ Object
- #manual? ⇒ Boolean
- #path ⇒ Object
- #platforms ⇒ Object
- #resources ⇒ Object
- #to_index_formula ⇒ Object
Constructor Details
#initialize(data, path) ⇒ Formula
Returns a new instance of Formula.
53 54 55 56 |
# File 'lib/fontist/formula.rb', line 53 def initialize(data, path) @data = data @path = path end |
Class Method Details
.all ⇒ Object
12 13 14 15 16 |
# 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) ⇒ Object
18 19 20 |
# 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) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# 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) ⇒ Object
22 23 24 |
# 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) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# 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_from_file(path) ⇒ Object
48 49 50 51 |
# File 'lib/fontist/formula.rb', line 48 def self.new_from_file(path) data = YAML.load_file(path) new(data, path) end |
Instance Method Details
#copyright ⇒ Object
86 87 88 |
# File 'lib/fontist/formula.rb', line 86 def copyright @data["copyright"] end |
#description ⇒ Object
78 79 80 |
# File 'lib/fontist/formula.rb', line 78 def description @data["description"] end |
#digest ⇒ Object
134 135 136 |
# File 'lib/fontist/formula.rb', line 134 def digest @data["digest"] end |
#downloadable? ⇒ Boolean
66 67 68 |
# File 'lib/fontist/formula.rb', line 66 def downloadable? @data.key?("resources") end |
#extract ⇒ Object
106 107 108 |
# File 'lib/fontist/formula.rb', line 106 def extract Helpers.parse_to_object(@data["extract"]) end |
#file_size ⇒ Object
110 111 112 113 114 |
# File 'lib/fontist/formula.rb', line 110 def file_size return unless @data["resources"] @data["resources"].values.first["file_size"]&.to_i end |
#fonts ⇒ Object
130 131 132 |
# File 'lib/fontist/formula.rb', line 130 def fonts @fonts ||= Helpers.parse_to_object(fonts_by_family) end |
#fonts_by_name(name) ⇒ Object
124 125 126 127 128 |
# File 'lib/fontist/formula.rb', line 124 def fonts_by_name(name) fonts.select do |font| font.name.casecmp?(name) end end |
#homepage ⇒ Object
82 83 84 |
# File 'lib/fontist/formula.rb', line 82 def homepage @data["homepage"] end |
#instructions ⇒ Object
120 121 122 |
# File 'lib/fontist/formula.rb', line 120 def instructions @data["instructions"] end |
#key ⇒ Object
74 75 76 |
# File 'lib/fontist/formula.rb', line 74 def key @data["key"] || default_key end |
#license ⇒ Object
94 95 96 |
# File 'lib/fontist/formula.rb', line 94 def license @data["open_license"] || @data["requires_license_agreement"] end |
#license_required ⇒ Object
98 99 100 |
# File 'lib/fontist/formula.rb', line 98 def license_required @data["requires_license_agreement"] ? true : false end |
#license_url ⇒ Object
90 91 92 |
# File 'lib/fontist/formula.rb', line 90 def license_url @data["license_url"] end |
#manual? ⇒ Boolean
62 63 64 |
# File 'lib/fontist/formula.rb', line 62 def manual? !downloadable? end |
#path ⇒ Object
70 71 72 |
# File 'lib/fontist/formula.rb', line 70 def path @path end |
#platforms ⇒ Object
102 103 104 |
# File 'lib/fontist/formula.rb', line 102 def platforms @data["platforms"] end |
#resources ⇒ Object
116 117 118 |
# File 'lib/fontist/formula.rb', line 116 def resources Helpers.parse_to_object(@data["resources"]&.values) end |
#to_index_formula ⇒ Object
58 59 60 |
# File 'lib/fontist/formula.rb', line 58 def to_index_formula Indexes::IndexFormula.new(path) end |