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[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.



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

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.



18
19
20
# File 'lib/fontist/import/formula_builder.rb', line 18

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.



18
19
20
# File 'lib/fontist/import/formula_builder.rb', line 18

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.



18
19
20
# File 'lib/fontist/import/formula_builder.rb', line 18

def font_files=(value)
  @font_files = value
end

#font_versionObject



55
56
57
# File 'lib/fontist/import/formula_builder.rb', line 55

def font_version
  @font_version
end

#import_sourceObject



51
52
53
# File 'lib/fontist/import/formula_builder.rb', line 51

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.



18
19
20
# File 'lib/fontist/import/formula_builder.rb', line 18

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.



18
19
20
# File 'lib/fontist/import/formula_builder.rb', line 18

def operations=(value)
  @operations = value
end

#options=(value) ⇒ Object (writeonly)

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



18
19
20
# File 'lib/fontist/import/formula_builder.rb', line 18

def options=(value)
  @options = value
end

#resources=(value) ⇒ Object

Sets the attribute resources

Parameters:

  • value

    the value to set the attribute resources to.



18
19
20
# File 'lib/fontist/import/formula_builder.rb', line 18

def resources=(value)
  @resources = value
end

Instance Method Details

#formulaObject



34
35
36
# File 'lib/fontist/import/formula_builder.rb', line 34

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

#saveObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fontist/import/formula_builder.rb', line 38

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

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

Convenience method to set Google import source



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

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



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

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



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

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