Class: Tag

Inherits:
ActiveRecord::Base
  • 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


17
18
19
20
21
22
23
# File 'app/models/tag.rb', line 17

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


9
10
11
12
13
14
15
# File 'app/models/tag.rb', line 9

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


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

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

#on(taggable) ⇒ Object


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

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

#taggedObject


52
53
54
# File 'app/models/tag.rb', line 52

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

#to_paramObject


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

def to_param
  humanized_param(name)
end

#to_sObject


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

def to_s
  name
end