Class: SimplerNavigation::Item
- Inherits:
-
Object
- Object
- SimplerNavigation::Item
- Defined in:
- lib/simpler_navigation/item.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #fetch(key) ⇒ Object
-
#initialize(key:, name:, url:, level: 0, options: {}) ⇒ Item
constructor
A new instance of Item.
- #item(key, name, url, options = {}) ⇒ Object
Constructor Details
#initialize(key:, name:, url:, level: 0, options: {}) ⇒ Item
Returns a new instance of Item.
9 10 11 12 13 14 15 16 |
# File 'lib/simpler_navigation/item.rb', line 9 def initialize(key:, name:, url:, level: 0, options: {}) @key = key @name = name @url = url @level = level @options = @children = {} end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
7 8 9 |
# File 'lib/simpler_navigation/item.rb', line 7 def children @children end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
5 6 7 |
# File 'lib/simpler_navigation/item.rb', line 5 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/simpler_navigation/item.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/simpler_navigation/item.rb', line 6 def @options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/simpler_navigation/item.rb', line 4 def url @url end |
Instance Method Details
#[](key) ⇒ Object
30 31 32 |
# File 'lib/simpler_navigation/item.rb', line 30 def [](key) @children[key] end |
#fetch(key) ⇒ Object
34 35 36 |
# File 'lib/simpler_navigation/item.rb', line 34 def fetch(key) @children.fetch(key) end |
#item(key, name, url, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/simpler_navigation/item.rb', line 18 def item(key, name, url, = {}) if @children[key] raise "Navigation item already exists for #{key.inspect}" end @children[key] = Item.new(key: key, name: name, url: url, level: @level + 1, options: ) if block_given? yield @children[key] end end |