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