Class: Lifer::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/lifer/tag.rb

Overview

A tag is a way to categorize entries. You’ve likely encountered tags in other software before. In Lifer, tags are sort of the inverse of collections. It’s a nice way to associate entries across many collections.

Because tags are used to link entries, we definitely do not want duplicate tags. So the only way to build or retrieve tags is via the ‘.build_or_update` class method, which helps us responsibly manage the global tag manifest.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, entries:) ⇒ Tag

Returns a new instance of Tag.



48
49
50
51
# File 'lib/lifer/tag.rb', line 48

def initialize(name:, entries:)
  @name = name
  @entries = entries
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



46
47
48
# File 'lib/lifer/tag.rb', line 46

def entries
  @entries
end

#nameObject

Returns the value of attribute name.



44
45
46
# File 'lib/lifer/tag.rb', line 44

def name
  @name
end

Class Method Details

.build_or_update(name:, entries: []) ⇒ Lifer:Tag

Builds or updates a Lifer tag. On update, its list of entries gets freshened.

Parameters:

  • name (String)

    The name of the tag.

  • entries (Array<Lifer::Entry>) (defaults to: [])

    A list of entries that should be associated with the tag. This parameter is not a true writer, in that if the tag already exists, old entry associations won’t be removed– only appended to.

Returns:

  • (Lifer:Tag)

    The new or updated tag.



22
23
24
# File 'lib/lifer/tag.rb', line 22

def build_or_update(name:, entries: [])
  update(name:, entries:) || build(name:, entries:)
end