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)


7
8
9
10
11
12
13
# File 'app/lib/burp/link.rb', line 7

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

Instance Attribute Details

#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



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

#hashObject



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

def hash
  to_hash.hash
end

#to_hashObject



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_paramObject



27
28
29
# File 'app/lib/burp/link.rb', line 27

def to_param
  id
end

#to_yamlObject



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