Sha256: fd04978b030be44dbad0175c9f084ecfba5d4ae2b075a5207c11fea7ca5ae74b
Contents?: true
Size: 889 Bytes
Versions: 3
Compression:
Stored size: 889 Bytes
Contents
require 'mechanize' module Screenshots class Page attr_reader :url, :title, :screenshot_name, :screenshot_url def initialize(url) @url = url @screenshot_name = generate_screenshot_name(@url) @blog_assets_url = Screenshots.configuration.blog_assets_url @screenshot_extension = Screenshots.configuration.image_extension agent = Mechanize.new agent.get(@url) do |page| @title = page.title end end def generate_blog_section section = "<h2><a href=\"#{@url}\">#{@title}</a></h2>\n" section += "<img src=\"#{screenshot_url}\" />\n" end def screenshot_url @screenshot_url ||= File.join(@blog_assets_url, @screenshot_name + "." + @screenshot_extension) end private def generate_screenshot_name(url) url.gsub(/(\:\/)*\//, '_') .gsub(/[\?=\+\\&]/, '_') end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
screenshots-0.0.3 | lib/screenshots/page.rb |
screenshots-0.0.2 | lib/screenshots/page.rb |
screenshots-0.0.1 | lib/screenshots/page.rb |