class Fontist::Import::CreateFormula

Public Class Methods

new(url, options = {}) click to toggle source
# File lib/fontist/import/create_formula.rb, line 11
def initialize(url, options = {})
  @url = url
  @options = options
end

Public Instance Methods

call() click to toggle source
# File lib/fontist/import/create_formula.rb, line 16
def call
  save(formula)
end

Private Instance Methods

archive() click to toggle source
# File lib/fontist/import/create_formula.rb, line 41
def archive
  @archive ||= download(@url)
end
download(url) click to toggle source
# File lib/fontist/import/create_formula.rb, line 45
def download(url)
  return url if File.exist?(url)

  Fontist::Utils::Downloader.download(url, progress_bar: true).path
end
extractor() click to toggle source
# File lib/fontist/import/create_formula.rb, line 34
def extractor
  @extractor ||=
    RecursiveExtraction.new(archive,
                            subarchive: @options[:subarchive],
                            subdir: @options[:subdir])
end
formula() click to toggle source
# File lib/fontist/import/create_formula.rb, line 22
def formula
  builder = FormulaBuilder.new
  builder.url = @url
  builder.archive = archive
  builder.extractor = extractor
  builder.options = @options
  builder.font_files = extractor.font_files
  builder.font_collection_files = extractor.font_collection_files
  builder.license_text = extractor.license_text
  builder.formula
end
save(hash) click to toggle source
# File lib/fontist/import/create_formula.rb, line 51
def save(hash)
  filename = Import.name_to_filename(hash[:name])
  path = @options[:formula_dir] ? File.join(@options[:formula_dir], filename) : filename
  yaml = YAML.dump(Helpers::HashHelper.stringify_keys(hash))
  File.write(path, yaml)
  path
end