Class: ImageFinderJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/image_finder_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(post) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/jobs/image_finder_job.rb', line 4

def perform(post)
  doc = Nokogiri::HTML::DocumentFragment.parse(post.body)

  doc.css('img').each do |img|
    size = FastImage.size img['src']

    next if size.nil?

    if size.min > 300
      post.update_attribute :picture_url, img['src']
      break
    end
  end
end