lib/fontist/import/formula_builder.rb in fontist-1.13.2 vs lib/fontist/import/formula_builder.rb in fontist-1.14.0

- old
+ new

@@ -2,13 +2,14 @@ require_relative "text_helper" module Fontist module Import class FormulaBuilder - FORMULA_ATTRIBUTES = %i[description homepage resources + FORMULA_ATTRIBUTES = %i[platforms description homepage resources font_collections fonts extract copyright - license_url open_license digest command].freeze + license_url requires_license_agreement + open_license digest command].freeze attr_writer :archive, :url, :extractor, :options, @@ -26,13 +27,19 @@ end def name return @options[:name] if @options[:name] - unique_names = both_fonts.map(&:family_name).uniq - TextHelper.longest_common_prefix(unique_names) || - both_fonts.first.family_name + common = %i[family_name type] + .map { |attr| both_fonts.map(&attr).uniq } + .map { |names| TextHelper.longest_common_prefix(names) } + .map { |prefix| prefix unless prefix == "Regular" } + .compact + .join(" ") + return common unless common.empty? + + both_fonts.map(&:family_name).first end private def formula_attributes @@ -48,10 +55,14 @@ raise Errors::FontNotFoundError, "No font found" if files.empty? files end + def platforms + @options[:platforms] + end + def description name end def homepage @@ -173,14 +184,19 @@ def license_url both_fonts.map(&:license_url).compact.first end + def requires_license_agreement + @options[:requires_license_agreement] + end + def open_license - unless @license_text + unless @license_text || requires_license_agreement Fontist.ui.error("WARN: please add license manually") - return end + + return unless @license_text Fontist.ui.error("WARN: ensure it's an open license, otherwise " \ "change the 'open_license' attribute to " \ "'requires_license_agreement'")