Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/doing/array.rb
Overview
Array helpers
Direct Known Subclasses
Instance Method Summary collapse
-
#highlight_tags(color = 'cyan') ⇒ String
Hightlight @tags in string for console output.
-
#log_tags ⇒ String
Tag array for logging.
-
#nested_hash(value) ⇒ Object
Convert array to nested hash, setting last key to value.
-
#tags_to_array ⇒ Array
Convert an @tags to plain strings.
-
#to_tags ⇒ Array
Convert strings to @tags.
- #to_tags! ⇒ Object
Instance Method Details
#highlight_tags(color = 'cyan') ⇒ String
Hightlight @tags in string for console output
39 40 41 42 |
# File 'lib/doing/array.rb', line 39 def (color = 'cyan') tag_color = Doing::Color.send(color) .map { |t| "#{tag_color}#{t}" } end |
#log_tags ⇒ String
Tag array for logging
49 50 51 |
# File 'lib/doing/array.rb', line 49 def .join(', ') end |
#nested_hash(value) ⇒ Object
Convert array to nested hash, setting last key to value
58 59 60 61 62 63 64 |
# File 'lib/doing/array.rb', line 58 def nested_hash(value) raise StandardError, 'Value can not be nil' if value.nil? hsh = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) } hsh.dig(*self[0..-2])[self.fetch(-1)] = value hsh end |
#tags_to_array ⇒ Array
Convert an @tags to plain strings
13 14 15 |
# File 'lib/doing/array.rb', line 13 def map { |t| t.sub(/^@/, '') } end |
#to_tags ⇒ Array
Convert strings to @tags
23 24 25 |
# File 'lib/doing/array.rb', line 23 def map { |t| t.sub(/^@?/, '@') } end |
#to_tags! ⇒ Object
27 28 29 |
# File 'lib/doing/array.rb', line 27 def replace end |