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[schema_version name platforms description homepage resources
font_collections fonts extract copyright
license_url requires_license_agreement
open_license digest command
import_source font_version].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFormulaBuilder

Returns a new instance of FormulaBuilder.



22
23
24
25
26
# File 'lib/fontist/import/formula_builder.rb', line 22

def initialize
  @options = {}
  @font_files = []
  @font_collection_files = []
end

Instance Attribute Details

#error_collector=(value) ⇒ Object (writeonly)

Sets the attribute error_collector

Parameters:

  • value

    the value to set the attribute error_collector to.



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

def error_collector=(value)
  @error_collector = 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

#font_versionObject



53
54
55
# File 'lib/fontist/import/formula_builder.rb', line 53

def font_version
  @font_version
end

#import_sourceObject



49
50
51
# File 'lib/fontist/import/formula_builder.rb', line 49

def import_source
  @import_source
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

#operations=(value) ⇒ Object (writeonly)

Sets the attribute operations

Parameters:

  • value

    the value to set the attribute operations to.



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

def operations=(value)
  @operations = 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

#resources=(value) ⇒ Object

Sets the attribute resources

Parameters:

  • value

    the value to set the attribute resources to.



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

def resources=(value)
  @resources = value
end

Instance Method Details

#formulaObject



28
29
30
# File 'lib/fontist/import/formula_builder.rb', line 28

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

#saveObject



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

def save
  path = path_from_name

  # Honor keep_existing option - don't overwrite if file exists and keep_existing is true
  if @options[:keep_existing] && File.exist?(path)
    return path
  end

  yaml = YAML.dump(Helpers::HashHelper.stringify_keys(formula))
  File.write(path, yaml)
  path
end

#schema_versionObject



45
46
47
# File 'lib/fontist/import/formula_builder.rb', line 45

def schema_version
  @options[:schema_version] || 4
end

#set_google_import_source(commit_id:, api_version:, last_modified:, family_id:) ⇒ Object

Convenience method to set Google import source



68
69
70
71
72
73
74
75
76
77
# File 'lib/fontist/import/formula_builder.rb', line 68

def set_google_import_source(commit_id:, api_version:, last_modified:,
family_id:)
  @import_source = GoogleImportSource.new(
    type: "google",
    commit_id: commit_id,
    api_version: api_version,
    last_modified: last_modified,
    family_id: family_id,
  )
end

#set_macos_import_source(framework_version:, posted_date:, asset_id:) ⇒ Object

Convenience method to set macOS import source



58
59
60
61
62
63
64
65
# File 'lib/fontist/import/formula_builder.rb', line 58

def set_macos_import_source(framework_version:, posted_date:, asset_id:)
  @import_source = MacosImportSource.new(
    type: "macos",
    framework_version: framework_version,
    posted_date: posted_date,
    asset_id: asset_id,
  )
end

#set_sil_import_source(version:, release_date:) ⇒ Object

Convenience method to set SIL import source



80
81
82
83
84
85
86
# File 'lib/fontist/import/formula_builder.rb', line 80

def set_sil_import_source(version:, release_date:)
  @import_source = SilImportSource.new(
    type: "sil",
    version: version,
    release_date: release_date,
  )
end