Class: HakumiComponents::Breadcrumb::Item::MenuEntry

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/components/hakumi_components/breadcrumb/item/menu_entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#hrefObject (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

#keyObject (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

#targetObject (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

#titleObject (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

Raises:

  • (ArgumentError)


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