Class: Burp::Link
- Inherits:
-
Object
- Object
- Burp::Link
- Defined in:
- app/lib/burp/link.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #current?(request = nil) ⇒ Boolean
- #current_class(request = nil) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(options) ⇒ Link
constructor
A new instance of Link.
- #to_hash ⇒ Object
- #to_html(request = nil, name = nil) ⇒ Object
- #to_param ⇒ Object
- #to_yaml ⇒ Object
- #update_id(parent_id) ⇒ Object
Constructor Details
#initialize(options) ⇒ Link
Returns a new instance of Link.
7 8 9 10 11 12 13 |
# File 'app/lib/burp/link.rb', line 7 def initialize() self.name = .keys.first self.url = .values.first raise ArgumentError.new("Missing a url") unless url raise ArgumentError.new("Missing a name") unless name end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'app/lib/burp/link.rb', line 4 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'app/lib/burp/link.rb', line 5 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'app/lib/burp/link.rb', line 5 def url @url end |
Class Method Details
.from_hash(hash) ⇒ Object
35 36 37 |
# File 'app/lib/burp/link.rb', line 35 def self.from_hash(hash) Link.new((hash[:name] || hash['name']) => (hash[:url] || hash['url'])) end |
.from_yaml(yaml) ⇒ Object
31 32 33 |
# File 'app/lib/burp/link.rb', line 31 def self.from_yaml(yaml) from_hash(YAML::load(yaml)) end |
Instance Method Details
#<=>(other) ⇒ Object
53 54 55 |
# File 'app/lib/burp/link.rb', line 53 def <=>(other) other.is_a?(Group) || other.is_a?(Link) ? name <=> other.name : 0 end |
#current?(request = nil) ⇒ Boolean
15 16 17 |
# File 'app/lib/burp/link.rb', line 15 def current?(request = nil) request && request.path == url end |
#current_class(request = nil) ⇒ Object
19 20 21 |
# File 'app/lib/burp/link.rb', line 19 def current_class(request = nil) current?(request) ? "current-url" : "" end |
#eql?(other) ⇒ Boolean
57 58 59 |
# File 'app/lib/burp/link.rb', line 57 def eql?(other) self.class == other.class && self.hash == other.hash end |
#hash ⇒ Object
61 62 63 |
# File 'app/lib/burp/link.rb', line 61 def hash to_hash.hash end |
#to_hash ⇒ Object
39 40 41 |
# File 'app/lib/burp/link.rb', line 39 def to_hash {:name => name, :url => url} end |
#to_html(request = nil, name = nil) ⇒ Object
23 24 25 |
# File 'app/lib/burp/link.rb', line 23 def to_html(request = nil,name = nil) %{<a class="#{current_class(request)}" #{id ? "id='#{id}'" : ""} href="#{url}">#{name || self.name}</a>}.html_safe end |
#to_param ⇒ Object
27 28 29 |
# File 'app/lib/burp/link.rb', line 27 def to_param id end |
#to_yaml ⇒ Object
43 44 45 |
# File 'app/lib/burp/link.rb', line 43 def to_yaml to_hash.to_yaml end |
#update_id(parent_id) ⇒ Object
48 49 50 |
# File 'app/lib/burp/link.rb', line 48 def update_id(parent_id) @id = {:parent_id => parent_id, :hash => self.hash}.hash end |