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.
16
17
18
|
# File 'app/models/tag.rb', line 16
def description
@description
end
|
#keywords ⇒ Object
Returns the value of attribute keywords.
16
17
18
|
# File 'app/models/tag.rb', line 16
def keywords
@keywords
end
|
Class Method Details
.collection_to_string(tags) ⇒ Object
54
55
56
57
|
# File 'app/models/tag.rb', line 54
def self.collection_to_string(tags)
tags.map(&:display_name).sort.
map { |name| / /.match?(name) ? "\"#{name}\"" : name }.join ", "
end
|
.create_from_article!(article) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/models/tag.rb', line 18
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
42
43
44
45
46
47
48
|
# File 'app/models/tag.rb', line 42
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
50
51
52
|
# File 'app/models/tag.rb', line 50
def self.find_with_char(char)
where("name LIKE ? ", "%#{char}%").order("name ASC")
end
|
Instance Method Details
#ensure_naming_conventions ⇒ Object
37
38
39
40
|
# File 'app/models/tag.rb', line 37
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
67
68
69
|
# File 'app/models/tag.rb', line 67
def feed_url(format)
"#{permalink_url}.#{format.gsub(/\d/, "")}"
end
|
#permalink ⇒ Object
63
64
65
|
# File 'app/models/tag.rb', line 63
def permalink
name
end
|
#permalink_url(_anchor = nil, only_path = false) ⇒ Object
71
72
73
|
# File 'app/models/tag.rb', line 71
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
59
60
61
|
# File 'app/models/tag.rb', line 59
def published_contents
contents.published
end
|