Class: Tag

Inherits:
ApplicationRecord
  • Object
show all
Includes:
PagesCore::HumanizableParam
Defined in:
app/models/tag.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PagesCore::HumanizableParam

#humanized_param

Class Method Details

.parse(*tags) ⇒ Object



22
23
24
25
26
27
28
# File 'app/models/tag.rb', line 22

def parse(*tags)
  Array(tags).flatten
             .map { |tag| tag.is_a?(Tag) ? tag.name : tag }
             .map { |tag| tag.split(",") }
             .flatten
             .map(&:strip)
end

.tags_and_suggestions_for(taggable, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'app/models/tag.rb', line 13

def tags_and_suggestions_for(taggable, options = {})
  limit = options[:limit] || 100
  tags = (taggable.tags.sorted + pinned.sorted).uniq

  return tags unless tags.count < limit

  tags + suggestions(taggable, tags, limit)[0...(limit - tags.length)]
end

Instance Method Details

#==(other) ⇒ Object



64
65
66
# File 'app/models/tag.rb', line 64

def ==(other)
  super || name == other.to_s
end

#on(taggable) ⇒ Object



60
61
62
# File 'app/models/tag.rb', line 60

def on(taggable)
  taggings.create(taggable:)
end

#taggedObject



56
57
58
# File 'app/models/tag.rb', line 56

def tagged
  @tagged ||= taggings.collect(&:taggable)
end

#to_paramObject



68
69
70
# File 'app/models/tag.rb', line 68

def to_param
  humanized_param(name)
end

#to_sObject



72
73
74
# File 'app/models/tag.rb', line 72

def to_s
  name
end