Files
danbooru/app/logical/post_sets/post.rb
2013-01-10 17:45:52 -05:00

73 lines
1.5 KiB
Ruby

module PostSets
class Post < Base
attr_reader :tag_array, :page
def initialize(tags, page = 1)
@tag_array = Tag.scan_query(tags)
@page = page
end
def tag_string
@tag_string ||= tag_array.uniq.join(" ")
end
def humanized_tag_string
tag_array.slice(0, 25).join(" ").tr("_", " ")
end
def has_wiki?
tag_array.any? && ::WikiPage.titled(tag_string).exists?
end
def wiki_page
if tag_array.any?
::WikiPage.titled(tag_string).first
else
nil
end
end
def has_explicit?
posts.any? {|x| x.rating == "e"}
end
def posts
if tag_array.size > 2 && !CurrentUser.is_privileged?
raise SearchError.new("Upgrade your account to search more than two tags at once")
end
@posts ||= ::Post.tag_match(tag_string).paginate(page, :count => ::Post.fast_count(tag_string))
rescue ::Post::SearchError
@posts = ::Post.where("false")
end
def has_artist?
tag_array.any? && ::Artist.name_equals(tag_string).exists?
end
def artist
::Artist.name_matches(tag_string).first
end
def is_single_tag?
tag_array.size == 1
end
def is_empty_tag?
tag_array.size == 0
end
def is_pattern_search?
tag_string =~ /\*/
end
def current_page
[page.to_i, 1].max
end
def presenter
@presenter ||= ::PostSetPresenters::Post.new(self)
end
end
end