Class: Burp::Link
- Inherits:
-
Object
- Object
- Burp::Link
- Defined in:
- app/lib/burp/link.rb
Instance Attribute Summary collapse
-
#css_class ⇒ Object
Returns the value of attribute css_class.
-
#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.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/lib/burp/link.rb', line 8 def initialize() self.name ||= [:name] self.url ||= [:url] self.css_class ||= [:class] 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
#css_class ⇒ Object
Returns the value of attribute css_class.
6 7 8 |
# File 'app/lib/burp/link.rb', line 6 def css_class @css_class end |
#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
40 41 42 |
# File 'app/lib/burp/link.rb', line 40 def self.from_hash(hash) Link.new((hash[:name] || hash['name']) => (hash[:url] || hash['url'])) end |
.from_yaml(yaml) ⇒ Object
36 37 38 |
# File 'app/lib/burp/link.rb', line 36 def self.from_yaml(yaml) from_hash(YAML::load(yaml)) end |
Instance Method Details
#<=>(other) ⇒ Object
58 59 60 |
# File 'app/lib/burp/link.rb', line 58 def <=>(other) other.is_a?(Group) || other.is_a?(Link) ? name <=> other.name : 0 end |
#current?(request = nil) ⇒ Boolean
20 21 22 |
# File 'app/lib/burp/link.rb', line 20 def current?(request = nil) request && request.path == url end |
#current_class(request = nil) ⇒ Object
24 25 26 |
# File 'app/lib/burp/link.rb', line 24 def current_class(request = nil) current?(request) ? "current-url" : "" end |
#eql?(other) ⇒ Boolean
62 63 64 |
# File 'app/lib/burp/link.rb', line 62 def eql?(other) self.class == other.class && self.hash == other.hash end |
#hash ⇒ Object
66 67 68 |
# File 'app/lib/burp/link.rb', line 66 def hash to_hash.hash end |
#to_hash ⇒ Object
44 45 46 |
# File 'app/lib/burp/link.rb', line 44 def to_hash {:name => name, :url => url} end |
#to_html(request = nil, name = nil) ⇒ Object
28 29 30 |
# File 'app/lib/burp/link.rb', line 28 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 |
#to_param ⇒ Object
32 33 34 |
# File 'app/lib/burp/link.rb', line 32 def to_param id end |
#to_yaml ⇒ Object
48 49 50 |
# File 'app/lib/burp/link.rb', line 48 def to_yaml to_hash.to_yaml end |
#update_id(parent_id) ⇒ Object
53 54 55 |
# File 'app/lib/burp/link.rb', line 53 def update_id(parent_id) @id = {:parent_id => parent_id, :hash => self.hash}.hash end |