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
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 14

def initialize(navigable, last: nil)
  @navigable = navigable
  @last = Taxon.new(name: last) if last.present?
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



43
44
45
46
47
48
49
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 43

def collection
  @collection ||= if last != breadcrumb_taxons.last
                    breadcrumb_taxons + [last]
                  else
                    breadcrumb_taxons
                  end
end

#join(sep = ' ') ⇒ Object



39
40
41
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 39

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)


35
36
37
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 35

def selected?(taxon)
  map(&:id).map(&:to_s).include?(taxon.id.to_s)
end

#to_global_idObject



19
20
21
22
# File 'app/models/workarea/navigation/breadcrumbs.rb', line 19

def to_global_id
  return nil unless navigable.present?
  navigable.to_global_id.to_param
end