Sha256: 7129086afb68523a1165139f3a5d63463ff4dd8c3c0ba40f5575c2e6e690550b

Contents?: true

Size: 2 KB

Versions: 19

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

KManager.action :array_commands do
  action do
    CmdletDirector
      .init(k_builder, category: :array)
      .cmdlet do
        name :join
        description           'join an array of values with separator as a string'
        result                'new String formed by joining the array elements with seperator'

        parameter             :values, 'array of values to join', param_type: 'String|Int'
        parameter             :separator, 'separator between values, defaults to comma', default: "','"

        ruby <<-RUBY
          return false if values.nil? || values.length == 0
          values = values.reject(&:blank?)
          return '' if values.length.zero?

          values.join(separator)
        RUBY
      end
      .cmdlet do
        name :join_pre
        description           'join an array of values with separator as a string and using the separator at the beginning of string'

        parameter             :values, 'array of values to join', param_type: 'String|Int'
        parameter             :separator, 'separator between values, defaults to comma', default: "','"

        ruby <<-'RUBY'
          return '' if values.nil? || !values.is_a?(::Array)
          values = values.reject(&:blank?)
          return '' if values.length.zero?

          "#{separator}#{values.join(separator)}"
        RUBY
      end
      .cmdlet do
        name :join_post
        description           'join an array of values with separator as a string and using the separator at the end of string'

        parameter             :values, 'array of values to join', param_type: 'String|Int'
        parameter             :separator, 'separator between values, defaults to comma', default: "','"

        ruby <<-'RUBY'
            return '' if values.nil? || !values.is_a?(::Array)
            values = values.reject(&:blank?)
            return '' if values.length.zero?

            "#{values.join(separator)}#{separator}"
        RUBY
      end
      .generate
      # .debug
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
cmdlet-0.14.0 .builders/generators/cmdlets/array.rb
cmdlet-0.13.2 .builders/generators/cmdlets/array.rb
cmdlet-0.13.1 .builders/generators/cmdlets/array.rb
cmdlet-0.13.0 .builders/generators/cmdlets/array.rb
cmdlet-0.12.5 .builders/generators/cmdlets/array.rb
cmdlet-0.12.4 .builders/generators/cmdlets/array.rb
cmdlet-0.12.3 .builders/generators/cmdlets/array.rb
cmdlet-0.12.2 .builders/generators/cmdlets/array.rb
cmdlet-0.12.1 .builders/generators/cmdlets/array.rb
cmdlet-0.12.0 .builders/generators/cmdlets/array.rb
cmdlet-0.11.0 .builders/generators/cmdlets/array.rb
cmdlet-0.10.1 .builders/generators/cmdlets/array.rb
cmdlet-0.10.0 .builders/generators/cmdlets/array.rb
cmdlet-0.9.2 .builders/generators/cmdlets/array.rb
cmdlet-0.9.1 .builders/generators/cmdlets/array.rb
cmdlet-0.9.0 .builders/generators/cmdlets/array.rb
cmdlet-0.8.0 .builders/generators/cmdlets/array.rb
cmdlet-0.7.1 .builders/generators/cmdlets/array.rb
cmdlet-0.7.0 .builders/generators/cmdlets/array.rb