Class: Burp::Group

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

Direct Known Subclasses

Menu

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Group

Returns a new instance of Group.



9
10
11
12
# File 'app/lib/burp/group.rb', line 9

def initialize(name,options = {})
  @name = name
  @children = (options[:children] || options['children']) || []
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



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

def children
  @children
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'app/lib/burp/group.rb', line 7

def name
  @name
end

Class Method Details

.bootstrap_nav(group, request) ⇒ Object



109
110
111
112
113
114
115
# File 'app/lib/burp/group.rb', line 109

def self.bootstrap_nav(group, request)
  %{
  <ul class="nav">
    #{group.children.map { |child| child.is_a?(Link) ? "<li class=\"#{child.css_class} #{child.current?(request) ? "active" : ""}\">#{child.to_html}</li>" : "" }.join("\n\t\t\t")}
  </ul>
  }.html_safe
end

.from_hash(hash) ⇒ Object



52
53
54
55
56
57
# File 'app/lib/burp/group.rb', line 52

def self.from_hash(hash)
  group = Group.new((hash[:name] || hash['name']),hash)
  group.children.map!{|child| (child[:url] || child['url']) ? Link.from_hash(child) : Group.from_hash(child)}
  
  group
end

.from_yaml(yaml) ⇒ Object



48
49
50
# File 'app/lib/burp/group.rb', line 48

def self.from_yaml(yaml)
  from_hash(YAML.load(yaml))
end

Instance Method Details

#<=>(other) ⇒ Object



97
98
99
# File 'app/lib/burp/group.rb', line 97

def <=>(other)
  other.is_a?(Group) || other.is_a?(Link) ? name <=> other.name : 0
end

#all_childrenObject



89
90
91
92
93
# File 'app/lib/burp/group.rb', line 89

def all_children
  children+children.map do |child|
    child.is_a?(Group) ? child.all_children : nil
  end.flatten.compact
end

#current?(request = nil) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'app/lib/burp/group.rb', line 33

def current?(request = nil)
  children.each do |child|
    return true if child.current?(request)
  end
  false
end

#current_class(request = nil) ⇒ Object



40
41
42
# File 'app/lib/burp/group.rb', line 40

def current_class(request = nil)
  "current-section" if current?(request)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
# File 'app/lib/burp/group.rb', line 101

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


44
45
46
# File 'app/lib/burp/group.rb', line 44

def first_link
  children.select {|v| v.is_a? Link}.first
end

#hashObject



105
106
107
# File 'app/lib/burp/group.rb', line 105

def hash
  to_hash.hash
end


74
75
76
# File 'app/lib/burp/group.rb', line 74

def links
  children.map {|child| child.is_a?(Group) ? child.links : child}.flatten
end

#to_hashObject



59
60
61
# File 'app/lib/burp/group.rb', line 59

def to_hash
  {:name => name, :children => children.map{|child| child.to_hash}}
end

#to_html(request = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/lib/burp/group.rb', line 14

def to_html(request = nil)
  
  if first_link
    first_link_in_group = %{<span class="first-link-in-group #{first_link.current_class(request)}">#{first_link.to_html(request,name)}</span>}
  else
    first_link_in_group = ""
  end
  
  
  %{
  <section #{id ? "id='#{id}'" : ""} class="group"><span class="group-name">#{name}</span>
    #{first_link_in_group}
    <ul class="children">
      #{children.inject("") do |x,link|  x += "<li class=\"child #{link.is_a?(Group) ? "group" : "link" } #{link.current_class(request)}\">#{link.to_html(request)}</li>" end}
    </ul>
  </section>
  }.html_safe      
end

#to_menuObject



67
68
69
70
71
72
# File 'app/lib/burp/group.rb', line 67

def to_menu
  menu = Menu.new(self.name)
  menu.children = Group.from_yaml(self.to_yaml).children
  
  menu
end

#to_paramObject



78
79
80
# File 'app/lib/burp/group.rb', line 78

def to_param
  id
end

#to_yamlObject



63
64
65
# File 'app/lib/burp/group.rb', line 63

def to_yaml
  to_hash.to_yaml
end

#update_id(parent_id) ⇒ Object



82
83
84
85
86
87
# File 'app/lib/burp/group.rb', line 82

def update_id(parent_id)
  @id = {:parent_id => parent_id, :hash => self.hash}.hash
  children.each_with_index do |child,index|
    child.update_id("#{self.id}#{index}")
  end
end