Method: ContentPreview::Parser#process_meta_data

Defined in:
lib/content-preview/parser.rb

#process_meta_data(document, url) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/content-preview/parser.rb', line 53

def (document, url)
  unless self.title
    unless document.css('title').empty?
      self.title = document.css('title').text
    end
  end

  if self.images.empty?
    list = []
    document.traverse do |el|
      [el[:src], el[:href]].grep(/\.(jpg)$/i).map{|l| URI.join(url, l).to_s}.first(10).each do |image|
        list << image
      end
    end

    self.images = list
  end

  unless self.description
    unless document.xpath('//meta[starts-with(@name, "")]').empty?
      for tag in document.xpath('//meta[starts-with(@name, "")]') do
        if %w(description).include?(tag.first.last)
          self.description = tag['content']
        end
      end
    end
  end
end