Class: Burp::Group
- Inherits:
-
Object
- Object
- Burp::Group
- Defined in:
- app/lib/burp/group.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #all_children ⇒ Object
- #current?(request = nil) ⇒ Boolean
- #current_class(request = nil) ⇒ Object
- #eql?(other) ⇒ Boolean
- #first_link ⇒ Object
- #hash ⇒ Object
-
#initialize(name, options = {}) ⇒ Group
constructor
A new instance of Group.
- #links ⇒ Object
- #to_hash ⇒ Object
- #to_html(request = nil) ⇒ Object
- #to_menu ⇒ Object
- #to_param ⇒ Object
- #to_yaml ⇒ Object
- #update_id(parent_id) ⇒ Object
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, = {}) @name = name @children = ([:children] || ['children']) || [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
6 7 8 |
# File 'app/lib/burp/group.rb', line 6 def children @children end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'app/lib/burp/group.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'app/lib/burp/group.rb', line 7 def name @name end |
Class Method Details
.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_children ⇒ Object
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
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
101 102 103 |
# File 'app/lib/burp/group.rb', line 101 def eql?(other) self.class == other.class && self.hash == other.hash end |
#first_link ⇒ Object
44 45 46 |
# File 'app/lib/burp/group.rb', line 44 def first_link children.select {|v| v.is_a? Link}.first end |
#hash ⇒ Object
105 106 107 |
# File 'app/lib/burp/group.rb', line 105 def hash to_hash.hash end |
#links ⇒ Object
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_hash ⇒ Object
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_menu ⇒ Object
67 68 69 70 71 72 |
# File 'app/lib/burp/group.rb', line 67 def = Menu.new(self.name) .children = Group.from_yaml(self.to_yaml).children end |
#to_param ⇒ Object
78 79 80 |
# File 'app/lib/burp/group.rb', line 78 def to_param id end |
#to_yaml ⇒ Object
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 |