Sha256: c3f87a58839cd2b94f44159ee6153fe497d43209add7533c0293c93841c92a66

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

%w{
uri

active_record
}.each { |m| require m }

module Murlsh

  # URL ActiveRecord.
  class Url < ActiveRecord::Base

    # Get the title of this url.
    def title
      ta = read_attribute(:title)
      ta = nil if ta and ta.empty?
      
      ua = read_attribute(:url)
      ua = nil if ua and ua.empty?

      ta || ua || '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

5 entries across 5 versions & 1 rubygems

Version Path
murlsh-0.10.0 lib/murlsh/url.rb
murlsh-0.9.0 lib/murlsh/url.rb
murlsh-0.8.1 lib/murlsh/url.rb
murlsh-0.8.0 lib/murlsh/url.rb
murlsh-0.7.0 lib/murlsh/url.rb