Class: Workarea::FindTaxonomySlug

Inherits:
Object
  • Object
show all
Defined in:
app/queries/workarea/find_taxonomy_slug.rb

Instance Method Summary collapse

Constructor Details

#initialize(navigable, taxon = nil) ⇒ FindTaxonomySlug

Returns a new instance of FindTaxonomySlug.



3
4
5
6
# File 'app/queries/workarea/find_taxonomy_slug.rb', line 3

def initialize(navigable, taxon = nil)
  @navigable = navigable
  @taxon = taxon || navigable.taxon
end

Instance Method Details

#slugObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/queries/workarea/find_taxonomy_slug.rb', line 8

def slug
  return unless @taxon.present?

  taxons = @taxon.ancestors_and_self
  taxons.shift # remove the first, root taxon

  slug =
    taxons
      .map { |t| t.navigable.try(:name) || t.name }
      .compact
      .map { |name| name.delete("'").parameterize }
      .join('-')

  FindUniqueSlug.new(@navigable, slug).slug
end