Class: Blog::Post
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Blog::Post
- Defined in:
- app/models/blog/post.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.tagged_with(name) ⇒ Object
8 9 10 |
# File 'app/models/blog/post.rb', line 8 def self.tagged_with(name) Tag.find_by_name!(name).posts.where('? >= published_at and draft = ?', DateTime.now, false).includes(:user) end |
Instance Method Details
#all_tags ⇒ Object
29 30 31 |
# File 'app/models/blog/post.rb', line 29 def self..map(&:name).join(", ") end |
#all_tags=(names) ⇒ Object
23 24 25 26 27 |
# File 'app/models/blog/post.rb', line 23 def (names) self. = names.split(",").map do |name| Tag.where(name: name.strip).first_or_create! end end |
#reading_time ⇒ Object
17 18 19 20 21 |
# File 'app/models/blog/post.rb', line 17 def reading_time words_per_minute = 150 text = Nokogiri::HTML(self.body).at('body').inner_text (text.scan(/\w+/).length / words_per_minute).to_i end |
#text ⇒ Object
12 13 14 15 |
# File 'app/models/blog/post.rb', line 12 def text return if .present? and !.blank? body if body.present? and !body.blank? end |