Class: Effective::Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::Post
- Includes:
- PgSearch::Model
- Defined in:
- app/models/effective/post.rb
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
Instance Method Summary collapse
- #approve! ⇒ Object
- #approved? ⇒ Boolean
-
#duplicate ⇒ Object
Returns a duplicated post object, or throws an exception.
- #duplicate! ⇒ Object
- #event? ⇒ Boolean
- #published? ⇒ Boolean
- #send_post_submitted! ⇒ Object
- #start_time ⇒ Object
-
#time_to_read_in_seconds(reading_speed = 3.333) ⇒ Object
3.333 words/second is the default reading speed.
- #to_s ⇒ Object
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
9 10 11 |
# File 'app/models/effective/post.rb', line 9 def current_user @current_user end |
Instance Method Details
#approve! ⇒ Object
145 146 147 |
# File 'app/models/effective/post.rb', line 145 def approve! update!(draft: false) end |
#approved? ⇒ Boolean
105 106 107 |
# File 'app/models/effective/post.rb', line 105 def approved? draft == false end |
#duplicate ⇒ Object
Returns a duplicated post object, or throws an exception
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/models/effective/post.rb', line 127 def duplicate post = Post.new(attributes.except('id', 'updated_at', 'created_at', 'tags')) post.assign_attributes( title: post.title + ' (Copy)', slug: post.slug + '-copy', draft: true, body: body, excerpt: excerpt ) post end |
#duplicate! ⇒ Object
141 142 143 |
# File 'app/models/effective/post.rb', line 141 def duplicate! duplicate.tap { |post| post.save! } end |
#event? ⇒ Boolean
109 110 111 |
# File 'app/models/effective/post.rb', line 109 def event? EffectivePosts.event_categories.include?(EffectivePosts.category(category)) end |
#published? ⇒ Boolean
101 102 103 |
# File 'app/models/effective/post.rb', line 101 def published? !draft? && published_at.present? && published_at < Time.zone.now end |
#send_post_submitted! ⇒ Object
122 123 124 |
# File 'app/models/effective/post.rb', line 122 def send_post_submitted! EffectivePosts.send_email(:post_submitted, self) end |
#start_time ⇒ Object
113 114 115 |
# File 'app/models/effective/post.rb', line 113 def start_time start_at end |
#time_to_read_in_seconds(reading_speed = 3.333) ⇒ Object
3.333 words/second is the default reading speed.
118 119 120 |
# File 'app/models/effective/post.rb', line 118 def time_to_read_in_seconds(reading_speed = 3.333) (regions.to_a.sum { |region| (region.content || '').scan(/\w+/).size } / reading_speed).seconds end |
#to_s ⇒ Object
97 98 99 |
# File 'app/models/effective/post.rb', line 97 def to_s title.presence || 'New Post' end |