Sha256: 7526e6a77ba13122a235466e5f83b7dc93bb10ed91ca1e5af6961d056135379e

Contents?: true

Size: 1.03 KB

Versions: 14

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Doing
  ##
  ## Array helpers
  ##
  class ::Array
    ##
    ## Convert an array of @tags to plain strings
    ##
    ## @return     [Array] array of strings
    ##
    def tags_to_array
      map(&:remove_at).map(&:strip)
    end

    # Convert array of strings to array of @tags
    #
    # @return     [Array] Array of @tags
    #
    # @example
    #   ['one', '@two', 'three'].to_tags
    #   # => ['@one', '@two', '@three']
    def to_tags
      map(&:add_at)
    end

    ##
    ## Hightlight @tags in string for console output
    ##
    ## @param      color  [String] the color to highlight
    ##                    with
    ##
    ## @return     [Array] Array of highlighted @tags
    ##
    def highlight_tags(color = 'cyan')
      to_tags.map { |t| Doing::Color.send(color.to_sym, t) }
    end

    ##
    ## Tag array for logging
    ##
    ## @return     [String] Highlighted tag array joined with comma
    ##
    def log_tags(color = 'cyan')
      highlight_tags(color).join(', ')
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
doing-2.1.40 lib/doing/array/tags.rb
doing-2.1.39 lib/doing/array/tags.rb
doing-2.1.38 lib/doing/array/tags.rb
doing-2.1.37 lib/doing/array/tags.rb
doing-2.1.36 lib/doing/array/tags.rb
doing-2.1.35 lib/doing/array/tags.rb
doing-2.1.34 lib/doing/array/tags.rb
doing-2.1.33 lib/doing/array/tags.rb
doing-2.1.32 lib/doing/array/tags.rb
doing-2.1.31pre lib/doing/array/tags.rb
doing-2.1.30 lib/doing/array/tags.rb
doing-2.1.29 lib/doing/array/tags.rb
doing-2.1.28 lib/doing/array/tags.rb
doing-2.1.27 lib/doing/array/tags.rb