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.
23 24 25 |
# File 'app/models/effective/post.rb', line 23 def current_user @current_user end |
Instance Method Details
#approve! ⇒ Object
154 155 156 |
# File 'app/models/effective/post.rb', line 154 def approve! update!(draft: false) end |
#approved? ⇒ Boolean
117 118 119 |
# File 'app/models/effective/post.rb', line 117 def approved? draft == false end |
#duplicate ⇒ Object
Returns a duplicated post object, or throws an exception
139 140 141 142 143 144 145 146 147 148 |
# File 'app/models/effective/post.rb', line 139 def duplicate Post.new(attributes.except('id', 'updated_at', 'created_at')).tap do |post| post.title = post.title + ' (Copy)' post.slug = post.slug + '-copy' post.draft = true post.body = body post.excerpt = excerpt end end |
#duplicate! ⇒ Object
150 151 152 |
# File 'app/models/effective/post.rb', line 150 def duplicate! duplicate.tap { |post| post.save! } end |
#event? ⇒ Boolean
121 122 123 |
# File 'app/models/effective/post.rb', line 121 def event? category == 'events' end |
#published? ⇒ Boolean
113 114 115 |
# File 'app/models/effective/post.rb', line 113 def published? !draft? && published_at.present? && published_at < Time.zone.now end |
#send_post_submitted! ⇒ Object
134 135 136 |
# File 'app/models/effective/post.rb', line 134 def send_post_submitted! EffectivePosts.send_email(:post_submitted, self) end |
#start_time ⇒ Object
125 126 127 |
# File 'app/models/effective/post.rb', line 125 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.
130 131 132 |
# File 'app/models/effective/post.rb', line 130 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
109 110 111 |
# File 'app/models/effective/post.rb', line 109 def to_s title.presence || 'New Post' end |