Class: Burp::Link

Inherits:
Object
  • Object
show all
Defined in:
app/lib/burp/link.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Link

Returns a new instance of Link.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
# File 'app/lib/burp/link.rb', line 8

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

Instance Attribute Details

#css_classObject

Returns the value of attribute css_class.



6
7
8
# File 'app/lib/burp/link.rb', line 6

def css_class
  @css_class
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'app/lib/burp/link.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'app/lib/burp/link.rb', line 5

def name
  @name
end

#urlObject

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

Returns:

  • (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

Returns:

  • (Boolean)


62
63
64
# File 'app/lib/burp/link.rb', line 62

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

#hashObject



66
67
68
# File 'app/lib/burp/link.rb', line 66

def hash
  to_hash.hash
end

#to_hashObject



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_paramObject



32
33
34
# File 'app/lib/burp/link.rb', line 32

def to_param
  id
end

#to_yamlObject



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