Class: Staticpress::Plugins::Menu::MenuItem

Inherits:
Object
  • Object
show all
Defined in:
lib/staticpress/plugins/menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position, text, url_path, sub_items = []) ⇒ MenuItem

Returns a new instance of MenuItem.



62
63
64
65
66
67
# File 'lib/staticpress/plugins/menu.rb', line 62

def initialize(position, text, url_path, sub_items = [])
  @position = position.to_i
  @text = text
  @url_path = url_path
  @sub_items = sub_items
end

Instance Attribute Details

#positionObject (readonly)

Returns the value of attribute position.



60
61
62
# File 'lib/staticpress/plugins/menu.rb', line 60

def position
  @position
end

#sub_itemsObject (readonly)

Returns the value of attribute sub_items.



60
61
62
# File 'lib/staticpress/plugins/menu.rb', line 60

def sub_items
  @sub_items
end

#textObject (readonly)

Returns the value of attribute text.



60
61
62
# File 'lib/staticpress/plugins/menu.rb', line 60

def text
  @text
end

#url_pathObject (readonly)

Returns the value of attribute url_path.



60
61
62
# File 'lib/staticpress/plugins/menu.rb', line 60

def url_path
  @url_path
end

Instance Method Details

#<=>(other) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/staticpress/plugins/menu.rb', line 69

def <=>(other)
  reply = case
    when (position < 0) && (other.position < 0) then other.position.abs <=> position.abs
    when (position < 0) || (other.position < 0) then other.position <=> position
    else                                             position <=> other.position
  end
  reply.zero? ? (text <=> other.text) : reply
end