Sha256: 19b068d57bac88066dcf5488d5dbfb7a1cdd124b09431d651104fa9dce9fc574

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module TailwindDsl
  module Etl
    module RawComponents
      # UiKit
      #
      # UiKit is a container for storing different tailwind design systems
      class UiKit
        attr_accessor :design_systems

        # Pass in a document with the keys symbolized
        #
        # JSON.parse(json, symbolize_names: true)
        #
        # @param document [Hash] the document to convert
        def initialize(document = nil)
          @design_systems = []

          return unless !document.nil? && document.is_a?(Hash) && document.key?(:design_systems) && document[:design_systems].is_a?(Array)

          document[:design_systems].each { |design_system| add_design_system(design_system) }
        end

        def add_design_system(design_system)
          add = convert_design_system(design_system)

          return nil if add.nil?

          add.name = add.name.to_s
          design_systems << add

          add
        end

        def design_system(name)
          find_name = name.to_s
          design_systems.find { |ds| ds.name == find_name }
        end

        def design_system?(name)
          !design_system(name).nil?
        end

        def to_h
          {
            design_systems: design_systems.map(&:to_h)
          }
        end

        private

        def convert_design_system(design_system)
          return nil if design_system.nil?

          return design_system if design_system.is_a?(DesignSystem)
          return DesignSystem.new(design_system) if design_system.is_a?(Hash)

          puts "Unknown design_system type: #{design_system.class}"
          nil
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tailwind_dsl-0.0.6 lib/tailwind_dsl/etl/raw_components/schema/uikit.rb
tailwind_dsl-0.0.5 lib/tailwind_dsl/etl/raw_components/schema/uikit.rb
tailwind_dsl-0.0.4 lib/tailwind_dsl/etl/raw_components/schema/uikit.rb