Class: Workarea::Navigation::Breadcrumbs

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/models/workarea/navigation/breadcrumbs.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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: breadcrumb_taxons.last
            )
          elsif last.present?
            Taxon.new(name: last, parent: breadcrumb_taxons.last)
          end
end

Instance Attribute Details

#lastObject (readonly)

Returns the value of attribute last.



6
7
8
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 6

def last
  @last
end

Returns the value of attribute navigable.



6
7
8
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 6

def navigable
  @navigable
end

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

#collectionObject



52
53
54
55
56
57
58
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 52

def collection
  @collection ||= if last != breadcrumb_taxons.last
                    breadcrumb_taxons + [last]
                  else
                    breadcrumb_taxons
                  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.

Parameters:

Returns:

  • (Boolean)


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_idObject



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