Sha256: ce1a4fff7fa59dd37ed9475217aee53f7b4eba5747698d2a1d520a640a616fcd

Contents?: true

Size: 1.49 KB

Versions: 30

Compression:

Stored size: 1.49 KB

Contents

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

    def initialize(options)      
      self.name ||= options[:name]
      self.url ||= options[:url]
      self.css_class ||= options[:class]
      
      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)} #{css_class}" #{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

30 entries across 30 versions & 1 rubygems

Version Path
burp_cms-1.7.1 app/lib/burp/link.rb
burp_cms-1.7.0 app/lib/burp/link.rb
burp_cms-1.6.0 app/lib/burp/link.rb
burp_cms-1.5.13 app/lib/burp/link.rb
burp_cms-1.5.12 app/lib/burp/link.rb
burp_cms-1.5.11 app/lib/burp/link.rb
burp_cms-1.5.10 app/lib/burp/link.rb
burp_cms-1.5.9 app/lib/burp/link.rb
burp_cms-1.5.8 app/lib/burp/link.rb
burp_cms-1.5.7 app/lib/burp/link.rb
burp_cms-1.5.6 app/lib/burp/link.rb
burp_cms-1.5.5 app/lib/burp/link.rb
burp_cms-1.5.4 app/lib/burp/link.rb
burp_cms-1.5.3 app/lib/burp/link.rb
burp_cms-1.5.2 app/lib/burp/link.rb
burp_cms-1.5.1 app/lib/burp/link.rb
burp_cms-1.5.0 app/lib/burp/link.rb
burp_cms-1.4.1 app/lib/burp/link.rb
burp_cms-1.4.0 app/lib/burp/link.rb
burp_cms-1.3.33 app/lib/burp/link.rb