Sha256: 1aec85116071291e07517dbacf94e37bc740feef22765f366e773abf34254403

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 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])
        yaml = YAML.dump(Helpers::HashHelper.stringify_keys(hash))
        File.write(filename, yaml)
        filename
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fontist-1.8.1 lib/fontist/import/create_formula.rb
fontist-1.7.3 lib/fontist/import/create_formula.rb
fontist-1.7.2 lib/fontist/import/create_formula.rb
fontist-1.7.1 lib/fontist/import/create_formula.rb
fontist-1.7.0 lib/fontist/import/create_formula.rb