Sha256: 07a049ad8f9b7a000d84161dd7b61b2c3b24b5258ff5dec5cf272bb71d55992c

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

module Pennyworth
  module Kits
    # Provides String utilities.
    class String
      # Builds a string from an array.
      # ==== Parameters
      # * +array+ - Required. The array to build a string from.
      # * +delimiter+ - Optional. The delimiter used to join each array element. Default: ' '
      def self.array_to_string array, delimiter = ' '
        array * delimiter
      end

      # Converts and outputs a string array as a downcased string.
      # ==== Parameters
      # * +array+ - Required. The string array to process.
      def self.downcase array
        string = Pennyworth::Kits::String.array_to_string array
        puts Pennyworth::Kits::Clipboard.copy(string.downcase)
      end

      # Converts and outputs a string array as an upcased string.
      # ==== Parameters
      # * +array+ - Required. The string array to process.
      def self.upcase array
        string = Pennyworth::Kits::String.array_to_string array
        puts Pennyworth::Kits::Clipboard.copy(string.upcase)
      end

      # Converts and outputs a string array as a capitalized string.
      # ==== Parameters
      # * +array+ - Required. The string array to process.
      def self.capitalize array
        words = array.map {|word| word.capitalize}
        words = Pennyworth::Kits::String.array_to_string words
        puts Pennyworth::Kits::Clipboard.copy(words)
      end

      # Converts a string array to a single string and outputs the string length.
      # ==== Parameters
      # * +array+ - Required. The string array to process.
      def self.length array
        string = Pennyworth::Kits::String.array_to_string array
        Pennyworth::Kits::Clipboard.copy(string)
        puts string.length
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pennyworth-3.1.0 lib/pennyworth/kits/string.rb
pennyworth-3.0.0 lib/pennyworth/kits/string.rb