Class: Trestle::Navigation::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/navigation/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Group.



6
7
8
9
# File 'lib/trestle/navigation/group.rb', line 6

def initialize(name, options={})
  @name = name
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/trestle/navigation/group.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/trestle/navigation/group.rb', line 4

def options
  @options
end

Instance Method Details

#<=>(other) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/trestle/navigation/group.rb', line 20

def <=>(other)
  case other
  when Group
    priority <=> other.priority
  when NullGroup
    1
  end
end

#==(other) ⇒ Object Also known as: eql?



11
12
13
# File 'lib/trestle/navigation/group.rb', line 11

def ==(other)
  other.is_a?(self.class) && name == other.name
end

#hashObject



16
17
18
# File 'lib/trestle/navigation/group.rb', line 16

def hash
  name.hash
end

#idObject



48
49
50
# File 'lib/trestle/navigation/group.rb', line 48

def id
  name.to_s.parameterize
end

#labelObject



44
45
46
# File 'lib/trestle/navigation/group.rb', line 44

def label
  I18n.t("admin.navigation.groups.#{name}", default: name.to_s.titlecase)
end

#merge(other) ⇒ Object



29
30
31
# File 'lib/trestle/navigation/group.rb', line 29

def merge(other)
  self.class.new(name, options.merge(other.options))
end

#priorityObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/trestle/navigation/group.rb', line 33

def priority
  case options[:priority]
  when :first
    -Float::INFINITY
  when :last
    Float::INFINITY
  else
    options[:priority] || 0
  end
end