Sha256: 4f4af7f62435b917e75047dd2d380c9ab40531bb2d1527a9bdf1e7c4075434eb

Contents?: true

Size: 1.21 KB

Versions: 41

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Doing
  ##
  ## Array helpers
  ##
  module ArrayTags
    ##
    ## Convert an array of @tags to plain strings
    ##
    ## @return     [Array] array of strings without @ symbols
    ##
    ## @example Convert an array of tags to strings
    ##   ['@one', '@two', 'three'].to_tags => ['one', 'two', 'three']
    def tags_to_array
      map(&:remove_at).map(&:strip)
    end

    # Convert array of strings to array of @tags
    #
    # @return     [Array] Array of @tags
    #
    # @example Convert an array of strings with or without @ symbols
    #   ['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

41 entries across 41 versions & 1 rubygems

Version Path
doing-2.1.88 lib/doing/array/tags.rb
doing-2.1.87 lib/doing/array/tags.rb
doing-2.1.86 lib/doing/array/tags.rb
doing-2.1.85 lib/doing/array/tags.rb
doing-2.1.84 lib/doing/array/tags.rb
doing-2.1.83 lib/doing/array/tags.rb
doing-2.1.82 lib/doing/array/tags.rb
doing-2.1.81 lib/doing/array/tags.rb
doing-2.1.80 lib/doing/array/tags.rb
doing-2.1.79 lib/doing/array/tags.rb
doing-2.1.78 lib/doing/array/tags.rb
doing-2.1.77 lib/doing/array/tags.rb
doing-2.1.76 lib/doing/array/tags.rb
doing-2.1.75 lib/doing/array/tags.rb
doing-2.1.74 lib/doing/array/tags.rb
doing-2.1.73 lib/doing/array/tags.rb
doing-2.1.72 lib/doing/array/tags.rb
doing-2.1.69 lib/doing/array/tags.rb
doing-2.1.68 lib/doing/array/tags.rb
doing-2.1.66 lib/doing/array/tags.rb