Sha256: 62ad5076b1d5e56d0282e8754fb2dc8748e3b32bbbce7543a7e93e57ec5152d2

Contents?: true

Size: 1.32 KB

Versions: 23

Compression:

Stored size: 1.32 KB

Contents

module Burp
  class Link
    
    attr_reader :id
    attr_accessor :url,:name

    def initialize(options)
      self.name = options.keys.first
      self.url = options.values.first

      raise ArgumentError.new("Missing a url") unless url
      raise ArgumentError.new("Missing a name") unless name
    end

    def current?(request = nil)
      request && request.path == url
    end

    def current_class(request = nil)
      current?(request) ? "current-url" : ""
    end

    def to_html(request = nil,name = nil)
      %{<a class="#{current_class(request)}" #{id ? "id='#{id}'" : ""} href="#{url}">#{name || self.name}</a>}.html_safe
    end
    
    def to_param
      id
    end
    
    def self.from_yaml(yaml)
      from_hash(YAML::load(yaml))
    end

    def self.from_hash(hash)
      Link.new((hash[:name] || hash['name']) => (hash[:url] || hash['url']))
    end
    
    def to_hash
      {:name => name, :url => url}
    end

    def to_yaml
      to_hash.to_yaml
    end
    
    
    def update_id(parent_id)
      @id = {:parent_id => parent_id, :hash => self.hash}.hash
    end
    
    
    def <=>(other)
      other.is_a?(Group) || other.is_a?(Link) ? name <=> other.name : 0
    end

    def eql?(other)
      self.class == other.class && self.hash == other.hash
    end

    def hash
      to_hash.hash
    end
    
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
burp_cms-1.3.22 app/lib/burp/link.rb
burp_cms-1.3.21 app/lib/burp/link.rb
burp_cms-1.3.20 app/lib/burp/link.rb
burp_cms-1.3.19 app/lib/burp/link.rb
burp_cms-1.3.18 app/lib/burp/link.rb
burp_cms-1.3.17 app/lib/burp/link.rb
burp_cms-1.3.16 app/lib/burp/link.rb
burp_cms-1.3.15 app/lib/burp/link.rb
burp_cms-1.3.14 app/lib/burp/link.rb
burp_cms-1.3.13 app/lib/burp/link.rb
burp_cms-1.3.12 app/lib/burp/link.rb
burp_cms-1.3.11 app/lib/burp/link.rb
burp_cms-1.3.10 app/lib/burp/link.rb
burp_cms-1.3.9 app/lib/burp/link.rb
burp_cms-1.3.8 app/lib/burp/link.rb
burp_cms-1.3.7 app/lib/burp/link.rb
burp_cms-1.3.6 app/lib/burp/link.rb
burp_cms-1.3.5 app/lib/burp/link.rb
burp_cms-1.3.4 app/lib/burp/link.rb
burp_cms-1.3.3 app/lib/burp/link.rb