Class: TopMenuItem

Inherits:
Object
  • Object
show all
Defined in:
app/models/top_menu_item.rb

Overview

Public: Instances of TopMenuItem should be instantiated from segments contained in SiteSetting.top_menu. Exposes relevant properties and methods that dictate which query methods should be called from the ListController. Segment data should start with a route fragment in one of the following formats:

a topic route, such as 'latest' or 'new' (see ListController for valid options)
the literal string "categories"
a specific category route, must start with 'category/' followed by the route, i.e. 'category/xyz'

A topic route can optionally specify a single category to exclude using the ‘-category’ option, i.e. ‘new,-xyz’

Examples

item = TopMenuItem.new('unread')
item.name           # => "unread"

item = TopMenuItem.new('latest,-video')
item.name           # => "latest"
item.has_filter?    # => true
item.filter         # => "video"

item = TopMenuItem.new('category/hardware')
item.name                     # => "category"
item.has_filter?              # => false
item.has_specific_category?   # => true
item.specific_category        # => "hardware"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ TopMenuItem

Returns a new instance of TopMenuItem.



28
29
30
31
32
# File 'app/models/top_menu_item.rb', line 28

def initialize(value)
  parts = value.split(",")
  @name = parts[0]
  @filter = initialize_filter(parts[1])
end

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter.



34
35
36
# File 'app/models/top_menu_item.rb', line 34

def filter
  @filter
end

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'app/models/top_menu_item.rb', line 34

def name
  @name
end

Instance Method Details

#has_filter?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/top_menu_item.rb', line 36

def has_filter?
  filter.present?
end

#has_specific_category?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/top_menu_item.rb', line 40

def has_specific_category?
  name.split("/")[0] == "category"
end

#specific_categoryObject



44
45
46
# File 'app/models/top_menu_item.rb', line 44

def specific_category
  name.split("/")[1]
end