Class: Tag
Constant Summary
StringLengthLimit::STRING_LIMIT
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
15
16
17
|
# File 'app/models/tag.rb', line 15
def description
@description
end
|
#keywords ⇒ Object
Returns the value of attribute keywords.
15
16
17
|
# File 'app/models/tag.rb', line 15
def keywords
@keywords
end
|
Class Method Details
.collection_to_string(tags) ⇒ Object
53
54
55
56
|
# File 'app/models/tag.rb', line 53
def self.collection_to_string(tags)
tags.map(&:display_name).sort
.map { |name| name.include?(" ") ? "\"#{name}\"" : name }.join ", "
end
|
.create_from_article!(article) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/models/tag.rb', line 17
def self.create_from_article!(article)
return if article.keywords.nil?
tags = []
Tag.transaction do
tagwords = article.keywords.to_s.scan(/((['"]).*?\2|[.:[[:alnum:]]]+)/).map do |x|
x.first.tr("\"'", "")
end
tagwords.uniq.each do |tagword|
tagname = tagword.to_url
tags << article.blog.tags.find_or_create_by(name: tagname) do |tag|
tag.display_name = tagword
end
end
end
article.tags = tags
tags
end
|
.find_all_with_content_counters ⇒ Object
41
42
43
44
45
46
47
|
# File 'app/models/tag.rb', line 41
def self.find_all_with_content_counters
Tag.joins(:contents)
.where(contents: { state: "published" })
.select(*Tag.column_names, "COUNT(contents_tags.content_id) as content_counter")
.group(*Tag.column_names)
.order("content_counter DESC").limit(1000)
end
|
.find_with_char(char) ⇒ Object
49
50
51
|
# File 'app/models/tag.rb', line 49
def self.find_with_char(char)
where("name LIKE ? ", "%#{char}%").order("name ASC")
end
|
Instance Method Details
#ensure_naming_conventions ⇒ Object
36
37
38
39
|
# File 'app/models/tag.rb', line 36
def ensure_naming_conventions
self.display_name = name if display_name.blank?
self.name = display_name.to_url if display_name.present?
end
|
#feed_url(format) ⇒ Object
66
67
68
|
# File 'app/models/tag.rb', line 66
def feed_url(format)
"#{permalink_url}.#{format.gsub(/\d/, "")}"
end
|
#permalink ⇒ Object
62
63
64
|
# File 'app/models/tag.rb', line 62
def permalink
name
end
|
#permalink_url(_anchor = nil, only_path = false) ⇒ Object
70
71
72
|
# File 'app/models/tag.rb', line 70
def permalink_url(_anchor = nil, only_path = false)
blog.url_for(controller: "tags", action: "show", id: permalink, only_path: only_path)
end
|
#published_contents ⇒ Object
58
59
60
|
# File 'app/models/tag.rb', line 58
def published_contents
contents.published
end
|