Class: Reviewable::Conversation::Post
- Inherits:
-
Object
- Object
- Reviewable::Conversation::Post
- Includes:
- ActiveModel::Serialization
- Defined in:
- lib/reviewable/conversation.rb
Instance Attribute Summary collapse
-
#excerpt ⇒ Object
readonly
Returns the value of attribute excerpt.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(post) ⇒ Post
constructor
A new instance of Post.
Constructor Details
#initialize(post) ⇒ Post
Returns a new instance of Post.
11 12 13 14 15 |
# File 'lib/reviewable/conversation.rb', line 11 def initialize(post) @user = post.user @id = post.id @excerpt = self.class.excerpt(post.cooked) end |
Instance Attribute Details
#excerpt ⇒ Object (readonly)
Returns the value of attribute excerpt.
9 10 11 |
# File 'lib/reviewable/conversation.rb', line 9 def excerpt @excerpt end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/reviewable/conversation.rb', line 9 def id @id end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
9 10 11 |
# File 'lib/reviewable/conversation.rb', line 9 def user @user end |
Class Method Details
.excerpt(cooked) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/reviewable/conversation.rb', line 17 def self.excerpt(cooked) excerpt = ::Post.excerpt(cooked, 250, keep_emoji_images: true) # remove the first link if it's the first node fragment = Nokogiri::HTML5.fragment(excerpt) if fragment.children.first == fragment.css("a:first").first && fragment.children.first fragment.children.first.remove end fragment.to_html.strip end |