Class: Kin::Nav::Item
- Inherits:
-
Object
- Object
- Kin::Nav::Item
- Defined in:
- lib/kin/nav.rb
Overview
Represents a single item/tab in a navigation menu.
Instance Attribute Summary collapse
-
#guard ⇒ Object
Returns the value of attribute guard.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#title(inject = nil) ⇒ String
Returns the item title (hover tooltip).
-
#url(given_resource = nil) ⇒ Object
Returns the URL for this Item.
Instance Method Summary collapse
-
#display?(guards = {}) ⇒ Boolean
Returns if this item can be displayed.
-
#initialize(id, label) ⇒ Item
constructor
private
A new instance of Item.
- #inspect ⇒ Object
-
#label(inject = nil) ⇒ String
Returns the item label.
Constructor Details
#initialize(id, label) ⇒ Item
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Item.
187 188 189 190 |
# File 'lib/kin/nav.rb', line 187 def initialize(id, label) @id, @label = id, label @resource, @url, @title, @guard = nil, nil, nil, nil end |
Instance Attribute Details
#guard ⇒ Object
Returns the value of attribute guard.
172 173 174 |
# File 'lib/kin/nav.rb', line 172 def guard @guard end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
171 172 173 |
# File 'lib/kin/nav.rb', line 171 def id @id end |
#resource ⇒ Object
Returns the value of attribute resource.
172 173 174 |
# File 'lib/kin/nav.rb', line 172 def resource @resource end |
#title(inject = nil) ⇒ String
Returns the item title (hover tooltip). If no title is set, the label will be used intead.
227 228 229 |
# File 'lib/kin/nav.rb', line 227 def title(inject = nil) @title || label(inject) end |
#url(given_resource = nil) ⇒ Object
Returns the URL for this Item. If the item expects a resource, it should be provided as the sole parameter to this method.
237 238 239 |
# File 'lib/kin/nav.rb', line 237 def url(given_resource = nil) expects_resource? ? resource_url(given_resource) : @url end |
Instance Method Details
#display?(guards = {}) ⇒ Boolean
Returns if this item can be displayed.
198 199 200 |
# File 'lib/kin/nav.rb', line 198 def display?(guards = {}) @guard.nil? || guards[@guard] end |
#inspect ⇒ Object
175 176 177 |
# File 'lib/kin/nav.rb', line 175 def inspect "#<Kin::Nav::Item #{id}>" end |
#label(inject = nil) ⇒ String
Returns the item label.
212 213 214 |
# File 'lib/kin/nav.rb', line 212 def label(inject = nil) inject ? @label % inject : @label end |