about summary refs log tree commit diff stats
path: root/app/models/quote.rb
blob: 3301667b3d017b2163f5c98f9c102be2f510addd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Quote < ApplicationRecord
  extend Enumerize

  include Votable

  acts_as_taggable

  has_one_attached :audio

  validates :content, presence: true

  enumerize :state,
    in: [:published, :pending, :hidden],
    default: :published,
    predicates: true

  scope :published, -> { where(state: :published) }
  scope :pending, -> { where(state: :pending) }

  def title
    "Quote \##{id}"
  end

  def published_date
    created_at.strftime("%B %d %Y at %I:%M:%S") + created_at.strftime(" %p").downcase + created_at.strftime(" %Z")
  end

  def has_extra?
    has_notes? or has_tags?
  end

  def has_notes?
    !notes.empty?
  end

  def has_tags?
    !tags.empty?
  end
end