Class: HakumiComponents::Breadcrumb::Item::MenuEntry
- Inherits:
-
Object
- Object
- HakumiComponents::Breadcrumb::Item::MenuEntry
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/breadcrumb/item/menu_entry.rb
Instance Attribute Summary collapse
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(title:, href: nil, target: nil, key: nil) ⇒ MenuEntry
constructor
A new instance of MenuEntry.
Constructor Details
#initialize(title:, href: nil, target: nil, key: nil) ⇒ MenuEntry
Returns a new instance of MenuEntry.
18 19 20 21 22 23 |
# File 'app/components/hakumi_components/breadcrumb/item/menu_entry.rb', line 18 def initialize(title:, href: nil, target: nil, key: nil) @title = T.let(title, String) @href = T.let(href, T.nilable(String)) @target = T.let(target, T.nilable(String)) @key = T.let(key || title, String) end |
Instance Attribute Details
#href ⇒ Object (readonly)
Returns the value of attribute href.
29 30 31 |
# File 'app/components/hakumi_components/breadcrumb/item/menu_entry.rb', line 29 def href @href end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
26 27 28 |
# File 'app/components/hakumi_components/breadcrumb/item/menu_entry.rb', line 26 def key @key end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
29 30 31 |
# File 'app/components/hakumi_components/breadcrumb/item/menu_entry.rb', line 29 def target @target end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
26 27 28 |
# File 'app/components/hakumi_components/breadcrumb/item/menu_entry.rb', line 26 def title @title end |
Class Method Details
.coerce(entry) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/components/hakumi_components/breadcrumb/item/menu_entry.rb', line 51 def self.coerce(entry) return entry if entry.is_a?(HakumiComponents::Breadcrumb::Item::MenuEntry) title = entry[:title] href = entry[:href] target = entry[:target] key = entry[:key] raise ArgumentError, "menu entry title is required" unless title.is_a?(String) && title.present? new( title: title, href: href.is_a?(String) ? href : nil, target: target.is_a?(String) ? target : nil, key: key.is_a?(String) ? key : nil ) end |
.coerce_all(entries) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'app/components/hakumi_components/breadcrumb/item/menu_entry.rb', line 36 def self.coerce_all(entries) return nil if entries.nil? coerced = T.let([], T::Array[HakumiComponents::Breadcrumb::Item::MenuEntry]) entries.each do |entry| coerced << coerce(entry) end coerced end |