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



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

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



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

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



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

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

#on(taggable) ⇒ Object



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

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

#taggedObject



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

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

#to_paramObject



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

def to_param
  humanized_param(name)
end

#to_sObject



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

def to_s
  name
end