Class: Railspress::Post
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Railspress::Post
- Includes:
- Entity, HasFocalPoint, Taggable
- Defined in:
- app/models/railspress/post.rb
Constant Summary
Constants included from Entity
Instance Attribute Summary collapse
-
#remove_header_image ⇒ Object
Virtual attribute for removing header image via checkbox.
Instance Method Summary collapse
-
#author ⇒ Object
Author association - only functional when Railspress.authors_enabled? The author class is configured via Railspress.configure { |c| c.author_class_name = “User” }.
- #author=(user) ⇒ Object
-
#calculate_reading_time ⇒ Object
Calculate reading time from content word count.
-
#display_status ⇒ Object
Returns the status to display in UI (accounts for scheduled state).
-
#live? ⇒ Boolean
Predicate: post is live (published_at in past or present).
-
#reading_time_display ⇒ Object
Display reading time with fallback to calculated value.
-
#scheduled? ⇒ Boolean
Predicate: post is scheduled for future publication.
Methods included from HasFocalPoint
#clear_image_override, #focal_point, #focal_point_css, #has_focal_point?, #has_image_override?, #image_css_for, #image_for, #image_override, #reset_focal_point!, #set_image_override
Methods included from Taggable
Instance Attribute Details
#remove_header_image ⇒ Object
Virtual attribute for removing header image via checkbox
49 50 51 |
# File 'app/models/railspress/post.rb', line 49 def remove_header_image @remove_header_image end |
Instance Method Details
#author ⇒ Object
Author association - only functional when Railspress.authors_enabled? The author class is configured via Railspress.configure { |c| c.author_class_name = “User” }
29 30 31 32 |
# File 'app/models/railspress/post.rb', line 29 def return nil unless .present? && Railspress. Railspress..find_by(id: ) end |
#author=(user) ⇒ Object
34 35 36 |
# File 'app/models/railspress/post.rb', line 34 def (user) self. = user&.id end |
#calculate_reading_time ⇒ Object
Calculate reading time from content word count
116 117 118 119 120 121 122 123 |
# File 'app/models/railspress/post.rb', line 116 def calculate_reading_time return 1 unless content.present? words_per_minute = Railspress.words_per_minute word_count = content.to_plain_text.split(/\s+/).count minutes = (word_count.to_f / words_per_minute).ceil [ minutes, 1 ].max end |
#display_status ⇒ Object
Returns the status to display in UI (accounts for scheduled state)
65 66 67 68 |
# File 'app/models/railspress/post.rb', line 65 def display_status return "scheduled" if published? && scheduled? status end |
#live? ⇒ Boolean
Predicate: post is live (published_at in past or present)
60 61 62 |
# File 'app/models/railspress/post.rb', line 60 def live? published_at.present? && published_at <= Time.current end |
#reading_time_display ⇒ Object
Display reading time with fallback to calculated value
126 127 128 |
# File 'app/models/railspress/post.rb', line 126 def reading_time_display reading_time.presence || calculate_reading_time end |
#scheduled? ⇒ Boolean
Predicate: post is scheduled for future publication
55 56 57 |
# File 'app/models/railspress/post.rb', line 55 def scheduled? published_at.present? && published_at > Time.current end |