Sha256: c2ffb728beaf4828f20b7b315d23cb22168380928c04b2cfe524ebba3233bd2f

Contents?: true

Size: 1.54 KB

Versions: 24

Compression:

Stored size: 1.54 KB

Contents

require "fontist/import"
require_relative "recursive_extraction"
require_relative "otf/font_file"
require_relative "files/collection_file"
require_relative "helpers/hash_helper"
require_relative "formula_builder"

module Fontist
  module Import
    class CreateFormula
      def initialize(url, options = {})
        @url = url
        @options = options
      end

      def call
        save(formula)
      end

      private

      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

      def extractor
        @extractor ||=
          RecursiveExtraction.new(archive,
                                  subarchive: @options[:subarchive],
                                  subdir: @options[:subdir])
      end

      def archive
        @archive ||= download(@url)
      end

      def download(url)
        return url if File.exist?(url)

        Fontist::Utils::Downloader.download(url, progress_bar: true).path
      end

      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
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
fontist-1.11.7 lib/fontist/import/create_formula.rb
fontist-1.11.6 lib/fontist/import/create_formula.rb
fontist-1.11.5 lib/fontist/import/create_formula.rb
fontist-1.11.3 lib/fontist/import/create_formula.rb
fontist-1.11.2 lib/fontist/import/create_formula.rb
fontist-1.9.3 lib/fontist/import/create_formula.rb
fontist-1.9.2 lib/fontist/import/create_formula.rb
fontist-1.11.1 lib/fontist/import/create_formula.rb
fontist-1.10.1 lib/fontist/import/create_formula.rb
fontist-1.10.0 lib/fontist/import/create_formula.rb
fontist-1.9.1 lib/fontist/import/create_formula.rb
fontist-1.9.0 lib/fontist/import/create_formula.rb
fontist-1.8.13 lib/fontist/import/create_formula.rb
fontist-1.8.12 lib/fontist/import/create_formula.rb
fontist-1.8.11 lib/fontist/import/create_formula.rb
fontist-1.8.10 lib/fontist/import/create_formula.rb
fontist-1.8.9 lib/fontist/import/create_formula.rb
fontist-1.8.8 lib/fontist/import/create_formula.rb
fontist-1.8.7 lib/fontist/import/create_formula.rb
fontist-1.8.6 lib/fontist/import/create_formula.rb