Sha256: 9d3dce6b27113ad8f6b9706f02ecbf9e69d2883abeab604a2015a90b516f55de

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module TailwindDsl
  module Etl
    module RawComponents
      # Group
      #
      # Group represents a collection of Tailwind CSS components withing a named group or category
      class Group
        attr_accessor :key
        attr_accessor :type
        attr_accessor :folder
        attr_accessor :sub_keys
        attr_accessor :files

        def initialize(key:, type:, folder:, sub_keys:, files: [])
          @key = key
          @type = type
          @folder = folder
          @sub_keys = sub_keys

          @files = []
          files.each { |file| add_file(file) }
        end

        def add_file(file)
          add = convert_file(file)

          return nil if add.nil?

          files << add

          add
        end

        def to_h
          {
            key: key,
            type: type,
            folder: folder,
            sub_keys: sub_keys,
            files: files.map(&:to_h)
          }
        end

        private

        def convert_file(file)
          return nil if file.nil?

          return file if file.is_a?(SourceFile)
          return SourceFile.new(file) if file.is_a?(Hash)

          puts "Unknown file type: #{file.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/group.rb
tailwind_dsl-0.0.5 lib/tailwind_dsl/etl/raw_components/schema/group.rb
tailwind_dsl-0.0.4 lib/tailwind_dsl/etl/raw_components/schema/group.rb