Class: Workarea::Navigation::Breadcrumbs
- Inherits:
-
Object
- Object
- Workarea::Navigation::Breadcrumbs
- Includes:
- Enumerable
- Defined in:
- app/models/workarea/navigation/breadcrumbs.rb
Instance Attribute Summary collapse
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#navigable ⇒ Object
readonly
Returns the value of attribute navigable.
-
#taxon_ids ⇒ Object
readonly
Returns the value of attribute taxon_ids.
Class Method Summary collapse
Instance Method Summary collapse
- #collection ⇒ Object
-
#initialize(navigable, last: nil) ⇒ Breadcrumbs
constructor
A new instance of Breadcrumbs.
- #join(sep = ' ') ⇒ Object
-
#selected?(taxon) ⇒ Boolean
Whether this link is selected in these breadcrumbs.
- #to_global_id ⇒ Object
Constructor Details
#initialize(navigable, last: nil) ⇒ Breadcrumbs
Returns a new instance of Breadcrumbs.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 14 def initialize(navigable, last: nil) @navigable = navigable @last = if last.class.include?(Navigable) Taxon.new( name: last.name, navigable: last, navigable_slug: last.slug, parent: .last ) elsif last.present? Taxon.new(name: last, parent: .last) end end |
Instance Attribute Details
#last ⇒ Object (readonly)
Returns the value of attribute last.
6 7 8 |
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 6 def last @last end |
#navigable ⇒ Object (readonly)
Returns the value of attribute navigable.
6 7 8 |
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 6 def navigable @navigable end |
#taxon_ids ⇒ Object (readonly)
Returns the value of attribute taxon_ids.
6 7 8 |
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 6 def taxon_ids @taxon_ids end |
Class Method Details
.from_global_id(via, last: nil) ⇒ Object
9 10 11 12 |
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 9 def self.from_global_id(via, last: nil) navigable = GlobalID::Locator.locate(via) new(navigable, last: last) end |
Instance Method Details
#collection ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 52 def collection @collection ||= if last != .last + [last] else end end |
#join(sep = ' ') ⇒ Object
48 49 50 |
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 48 def join(sep = ' ') collection.map(&:name).join(sep) end |
#selected?(taxon) ⇒ Boolean
Whether this link is selected in these breadcrumbs. Used to determine whether we should add a selected class when rendering navigation links.
44 45 46 |
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 44 def selected?(taxon) map(&:id).map(&:to_s).include?(taxon.id.to_s) end |
#to_global_id ⇒ Object
28 29 30 31 |
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 28 def to_global_id return nil unless navigable.present? navigable.to_global_id.to_param end |