Module: Doing::ArrayTags

Defined in:
lib/doing/array/tags.rb

Overview

Array helpers

Instance Method Summary collapse

Instance Method Details

#highlight_tags(color = 'cyan') ⇒ Array

Hightlight @tags in string for console output

Parameters:

  • color (String) (defaults to: 'cyan')

    the color to highlight with

Returns:

  • (Array)

    Array of highlighted @tags



37
38
39
# File 'lib/doing/array/tags.rb', line 37

def highlight_tags(color = 'cyan')
  to_tags.map { |t| Doing::Color.send(color.to_sym, t) }
end

#log_tags(color = 'cyan') ⇒ String

Tag array for logging

Returns:

  • (String)

    Highlighted tag array joined with comma



46
47
48
# File 'lib/doing/array/tags.rb', line 46

def log_tags(color = 'cyan')
  highlight_tags(color).join(', ')
end

#tags_to_arrayArray

Convert an array of @tags to plain strings

Examples:

Convert an array of tags to strings

['@one', '@two', 'three'].to_tags => ['one', 'two', 'three']

Returns:

  • (Array)

    array of strings without @ symbols



15
16
17
# File 'lib/doing/array/tags.rb', line 15

def tags_to_array
  map(&:remove_at).map(&:strip)
end

#to_tagsArray

Convert array of strings to array of @tags

Examples:

Convert an array of strings with or without @ symbols

['one', '@two', 'three'].to_tags => ['@one', '@two', '@three']

Returns:

  • (Array)

    Array of @tags



25
26
27
# File 'lib/doing/array/tags.rb', line 25

def to_tags
  map(&:add_at)
end