diff options
Diffstat (limited to 'app/models/quote.rb')
| -rw-r--r-- | app/models/quote.rb | 48 |
1 files changed, 48 insertions, 0 deletions
| diff --git a/app/models/quote.rb b/app/models/quote.rb new file mode 100644 index 0000000..b1d25b4 --- /dev/null +++ b/app/models/quote.rb | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | class Quote < ApplicationRecord | ||
| 2 | extend Enumerize | ||
| 3 | |||
| 4 | include Votable | ||
| 5 | |||
| 6 | acts_as_taggable | ||
| 7 | |||
| 8 | has_one_attached :audio | ||
| 9 | |||
| 10 | validates :content, presence: true | ||
| 11 | |||
| 12 | enumerize :state, | ||
| 13 | in: [:published, :pending, :hidden], | ||
| 14 | default: :published, | ||
| 15 | predicates: true | ||
| 16 | |||
| 17 | scope :published, -> { where(state: :published) } | ||
| 18 | scope :pending, -> { where(state: :pending) } | ||
| 19 | |||
| 20 | def title | ||
| 21 | "Quote \##{id}" | ||
| 22 | end | ||
| 23 | |||
| 24 | def published_date | ||
| 25 | created_at.strftime("%B %d %Y at %I:%M:%S") + created_at.strftime(" %p").downcase + created_at.strftime(" %Z") | ||
| 26 | end | ||
| 27 | |||
| 28 | def has_extra? | ||
| 29 | has_notes? or has_tags? | ||
| 30 | end | ||
| 31 | |||
| 32 | def has_notes? | ||
| 33 | !notes.empty? | ||
| 34 | end | ||
| 35 | |||
| 36 | def has_tags? | ||
| 37 | !tags.empty? | ||
| 38 | end | ||
| 39 | |||
| 40 | def self.ransackable_attributes(auth_object = nil) | ||
| 41 | ["content", "notes"] | ||
| 42 | end | ||
| 43 | |||
| 44 | def self.ransackable_associations(auth_object = nil) | ||
| 45 | [] | ||
| 46 | end | ||
| 47 | |||
| 48 | end | ||
