Sha256: d68f5cbb9b056e10f19a960f48afdc3cd2676784668eaf8a3a470fcf0f362698

Contents?: true

Size: 878 Bytes

Versions: 31

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

require 'faker'

module Uffizzi
  module ProjectHelper
    SLUG_ENDING_LENGTH = 6
    class << self
      def generate_default_params
        name = generate_name
        {
          name: name,
          description: default_description,
          slug: generate_slug(name),
        }
      end

      def generate_slug(name)
        formatted_name = name.downcase.gsub(/ /, '-').gsub(/[^\w-]+/, '')
        slug_ending = generate_random_string(SLUG_ENDING_LENGTH)

        "#{formatted_name}-#{slug_ending}"
      end

      private

      def generate_random_string(length)
        hexatridecimal_base = 36
        rand(hexatridecimal_base**length).to_s(hexatridecimal_base)
      end

      def default_description
        'Project generated by Uffizzi'
      end

      def generate_name
        Faker::Lorem.word
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
uffizzi-cli-2.4.11 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.10 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.9 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.8 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.7 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.6 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.5 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.4 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.3 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.2 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.1 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.4.0 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.3.4 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.3.3 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.3.2 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.3.1 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.3.0 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.2.2 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.2.1 lib/uffizzi/helpers/project_helper.rb
uffizzi-cli-2.2.0 lib/uffizzi/helpers/project_helper.rb