class Fontist::Import::Google::Models::FontFamily
Public Class Methods
Source
# File lib/fontist/import/google/models/font_family.rb, line 42 def initialize(**attributes) if attributes.key?(:files) files_value = attributes.delete(:files) attributes[:files_data] = files_value end super(**attributes) end
Initialize with support for files as Hash
Public Instance Methods
Source
# File lib/fontist/import/google/models/font_family.rb, line 155 def axes_count variable_font? ? axes.length : 0 end
Get the number of axes
@return [Integer] the number of axes
Source
# File lib/fontist/import/google/models/font_family.rb, line 110 def axis_by_tag(tag) return nil unless variable_font? axes.find { |axis| axis.tag == tag } end
Find an axis by its tag
@param tag [String] the axis tag (e.g., βwghtβ, βwdthβ) @return [Axis, nil] the axis if found, nil otherwise
Source
# File lib/fontist/import/google/models/font_family.rb, line 146 def custom_axes return [] unless variable_font? axes.select(&:custom_axis?) end
Get all custom (non-standard) axes
@return [Array<Axis>] array of custom axes
Source
# File lib/fontist/import/google/models/font_family.rb, line 169 def file_urls files ? files.values : [] end
Get all file URLs
@return [Array<String>] array of file URLs
Source
# File lib/fontist/import/google/models/font_family.rb, line 53 def files return {} if files_data.nil? return {} if files_data.respond_to?(:empty?) && files_data.empty? return files_data if files_data.is_a?(Hash) # Try to parse as JSON first begin JSON.parse(files_data) rescue JSON::ParserError, TypeError # If it fails, convert Ruby hash syntax to JSON and parse if files_data.is_a?(String) # Convert Ruby hash syntax (=>) to JSON syntax (:) json_str = files_data.gsub("=>", ":") begin return JSON.parse(json_str) rescue JSON::ParserError {} end end {} end end
Get files as a Hash
@return [Hash] hash of variant names to URLs
Source
# File lib/fontist/import/google/models/font_family.rb, line 79 def files=(value) self.files_data = value end
Set files from a Hash or JSON string
@param value [Hash, String] the files data
Source
# File lib/fontist/import/google/models/font_family.rb, line 137 def slant_axes return [] unless variable_font? axes.select(&:slant_axis?) end
Get all slant axes
@return [Array<Axis>] array of slant axes
Source
# File lib/fontist/import/google/models/font_family.rb, line 194 def summary parts = [family, version] parts << "(#{axes_count} axes)" if variable_font? parts.join(" ") end
Get a human-readable summary
@return [String] summary of the font family
Source
# File lib/fontist/import/google/models/font_family.rb, line 87 def variable_font? !axes.nil? && !axes.empty? end
Check if this is a variable font family Variable fonts have axes defined
@return [Boolean] true if axes are present and not empty
Source
# File lib/fontist/import/google/models/font_family.rb, line 177 def variant_exists?(variant_name) variant_names.include?(variant_name) end
Check if a specific variant exists
@param variant_name [String] the variant name @return [Boolean] true if variant exists
Source
# File lib/fontist/import/google/models/font_family.rb, line 162 def variant_names variants || [] end
Get all variant names
@return [Array<String>] array of variant names
Source
# File lib/fontist/import/google/models/font_family.rb, line 185 def variant_url(variant_name) return nil if files.nil? || files.empty? files[variant_name] end
Get URL for a specific variant
@param variant_name [String] the variant name @return [String, nil] the URL if found, nil otherwise
Source
# File lib/fontist/import/google/models/font_family.rb, line 97 def variants_by_format(format) return {} if files.nil? extension = format_extension(format) files.select do |_variant_name, url| url.end_with?(extension) end end
Get all variants in a specific format Note: This requires the files hash to contain URLs with the format extension
@param format [Symbol, String] the format (:ttf or :woff2) @return [Hash] hash of variant name to URL for the format
Source
# File lib/fontist/import/google/models/font_family.rb, line 119 def weight_axes return [] unless variable_font? axes.select(&:weight_axis?) end
Get all weight axes
@return [Array<Axis>] array of weight axes
Source
# File lib/fontist/import/google/models/font_family.rb, line 128 def width_axes return [] unless variable_font? axes.select(&:width_axis?) end
Get all width axes
@return [Array<Axis>] array of width axes