Sha256: e0b2fa4030179fc23fb33c9c6ff92c7ad2e0bcc022cb13db459a55a015fe329c
Contents?: true
Size: 1.14 KB
Versions: 2
Compression:
Stored size: 1.14 KB
Contents
require 'rubygems' require 'active_record' require 'uri' module Murlsh # URL ActiveRecord. class Url < ActiveRecord::Base # Get the title of this url. def title read_attribute(:title) || read_attribute(:url) || 'title missing' end # Title with whitespace compressed and leading and trailing whitespace # stripped. def title_stripped; title.strip.gsub(/\s+/, ' '); end # Return true if this url has the same author as another url. def same_author?(other) other and other.email and other.name and email and name and email == other.email and name == other.name end # Return text showing what domain a link goes to. def hostrec domain = Murlsh::failproof { URI(url).domain } domain = Murlsh::Plugin.hooks('hostrec').inject(domain) { |result,plugin| plugin.run(result, url, title) } yield domain if domain end # Yield the url that the url came from. def viarec; Murlsh::failproof { yield URI(via) } if via; end # Return true if this url is an image. def is_image? %w{image/gif image/jpeg image/png}.include?(content_type) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
murlsh-0.6.1 | lib/murlsh/url.rb |
murlsh-0.6.0 | lib/murlsh/url.rb |