Sha256: aa825f8d498e025858b996f104535daea3cffd19361b4b0ff979190bc26b6380

Contents?: true

Size: 833 Bytes

Versions: 1

Compression:

Stored size: 833 Bytes

Contents

module Ubiquitously
  class Page < Base
    attr_accessor :url, :title, :description, :tags, :image
    
    def initialize(attributes = {})
      apply attributes
    end
    
    def parse
      html = Nokogiri::HTML(open(url).read)
      
      self.title = html.xpath("//title").first.text.to_s.strip
      
      self.description = html.xpath("//meta[@name='description']").first["content"] rescue ""
      self.description.strip!
      
      self.tags = html.xpath("//meta[@name='keywords']").first["content"] rescue ""
      self.tags = self.tags.split(/,\s+/).taggify("-", ", ").split(", ")
      
      self.image = html.xpath("//link[@rel='image_src']").first["image_src"] rescue nil
      if self.image.blank?
        self.image = html.xpath("//img").first["src"] rescue nil
      end
      
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ubiquitously-0.1.0 lib/ubiquitously/models/page.rb