Sha256: 22d76ce3eb0c35c0a26493daf047ed24b19217e7721f1b184f5dde83fca13c6e

Contents?: true

Size: 837 Bytes

Versions: 7

Compression:

Stored size: 837 Bytes

Contents

module Fontist
  class Registry
    include Singleton

    def initialize
      @formulas ||= {}
    end

    def formulas
      parse_to_object(@formulas)
    end

    def self.formulas
      instance.formulas
    end

    def self.register(formula, key = nil)
      key ||= formula.instance.key || formula.to_s
      instance.register(formula, key)
    end

    def register(formula, key)
      @formulas[key] = build_formula_data(formula)
    end

    private

    def build_formula_data(formula)
      {
        installer: formula,
        fonts: formula.instance.fonts,
        license: formula.instance.license,
        homepage: formula.instance.homepage ,
        description: formula.instance.description,
      }
    end

    def parse_to_object(data)
      JSON.parse(data.to_json, object_class: OpenStruct)
    end
  end
end

Version data entries

7 entries across 6 versions & 2 rubygems

Version Path
fontist-1.2.1 lib/fontist/registry.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/fontist-1.1.0/lib/fontist/registry.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/fontist-1.2.0/lib/fontist/registry.rb
fontist-1.2.0 lib/fontist/registry.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/fontist-1.1.0/lib/fontist/registry.rb
fontist-1.1.0 lib/fontist/registry.rb
fontist-1.0.0 lib/fontist/registry.rb