Sha256: 7db7050692d43b2296c1609f6cb6a851787fc52e7848ea98a774c85c1ef5ca44

Contents?: true

Size: 1005 Bytes

Versions: 8

Compression:

Stored size: 1005 Bytes

Contents

require 'uri'

require 'active_record'

module Murlsh

  # URL ActiveRecord.
  class Url < ActiveRecord::Base
    validates_format_of :url, :with => URI.regexp

    # 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

    def ask
      if !defined?(@ask) or @ask.to_s != url
        @ask = URI(url).extend(Murlsh::UriAsk)
      end
      @ask
    end

    attr_accessor :user_supplied_title
    alias :user_supplied_title? :user_supplied_title
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
murlsh-1.7.0 lib/murlsh/url.rb
murlsh-1.6.1 lib/murlsh/url.rb
murlsh-1.6.0 lib/murlsh/url.rb
murlsh-1.5.0 lib/murlsh/url.rb
murlsh-1.4.1 lib/murlsh/url.rb
murlsh-1.4.0 lib/murlsh/url.rb
murlsh-1.3.1 lib/murlsh/url.rb
murlsh-1.3.0 lib/murlsh/url.rb