Class: Fontist::Import::FormulaBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/import/formula_builder.rb

Direct Known Subclasses

ManualFormulaBuilder

Constant Summary collapse

FORMULA_ATTRIBUTES =
i[platforms description homepage resources
font_collections fonts extract copyright
license_url requires_license_agreement
open_license digest command].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFormulaBuilder

Returns a new instance of FormulaBuilder.



21
22
23
# File 'lib/fontist/import/formula_builder.rb', line 21

def initialize
  @options = {}
end

Instance Attribute Details

#archive=(value) ⇒ Object (writeonly)

Sets the attribute archive

Parameters:

  • value

    the value to set the attribute archive to.



12
13
14
# File 'lib/fontist/import/formula_builder.rb', line 12

def archive=(value)
  @archive = value
end

#extractor=(value) ⇒ Object (writeonly)

Sets the attribute extractor

Parameters:

  • value

    the value to set the attribute extractor to.



12
13
14
# File 'lib/fontist/import/formula_builder.rb', line 12

def extractor=(value)
  @extractor = value
end

#font_collection_files=(value) ⇒ Object (writeonly)

Sets the attribute font_collection_files

Parameters:

  • value

    the value to set the attribute font_collection_files to.



12
13
14
# File 'lib/fontist/import/formula_builder.rb', line 12

def font_collection_files=(value)
  @font_collection_files = value
end

#font_files=(value) ⇒ Object (writeonly)

Sets the attribute font_files

Parameters:

  • value

    the value to set the attribute font_files to.



12
13
14
# File 'lib/fontist/import/formula_builder.rb', line 12

def font_files=(value)
  @font_files = value
end

#homepage=(value) ⇒ Object

Sets the attribute homepage

Parameters:

  • value

    the value to set the attribute homepage to.



12
13
14
# File 'lib/fontist/import/formula_builder.rb', line 12

def homepage=(value)
  @homepage = value
end

#license_text=(value) ⇒ Object (writeonly)

Sets the attribute license_text

Parameters:

  • value

    the value to set the attribute license_text to.



12
13
14
# File 'lib/fontist/import/formula_builder.rb', line 12

def license_text=(value)
  @license_text = value
end

#options=(value) ⇒ Object (writeonly)

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



12
13
14
# File 'lib/fontist/import/formula_builder.rb', line 12

def options=(value)
  @options = value
end

#url=(value) ⇒ Object (writeonly)

Sets the attribute url

Parameters:

  • value

    the value to set the attribute url to.



12
13
14
# File 'lib/fontist/import/formula_builder.rb', line 12

def url=(value)
  @url = value
end

Instance Method Details

#formulaObject



25
26
27
# File 'lib/fontist/import/formula_builder.rb', line 25

def formula
  formula_attributes.map { |name| [name, send(name)] }.to_h.compact
end

#nameObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fontist/import/formula_builder.rb', line 29

def name
  return @options[:name] if @options[: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