Class: Reviewable::Conversation::Post

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serialization
Defined in:
lib/reviewable/conversation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#excerptObject (readonly)

Returns the value of attribute excerpt.



9
10
11
# File 'lib/reviewable/conversation.rb', line 9

def excerpt
  @excerpt
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/reviewable/conversation.rb', line 9

def id
  @id
end

#userObject (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