Class: Workarea::ProductPrimaryNavigation

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

Instance Method Summary collapse

Constructor Details

#initialize(product, options = {}) ⇒ ProductPrimaryNavigation

Returns a new instance of ProductPrimaryNavigation.



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

def initialize(product, options = {})
  @product = product
  @options = options
end

Instance Method Details

#highest_categoryObject



23
24
25
26
27
28
# File 'app/queries/workarea/product_primary_navigation.rb', line 23

def highest_category
  @highest_category ||= categories
                          .select { |c| c.taxon.present? }
                          .sort { |a, b| a.taxon.depth <=> b.taxon.depth }
                          .first
end


18
19
20
21
# File 'app/queries/workarea/product_primary_navigation.rb', line 18

def main_nav_taxon
  return nil unless highest_category.try(:taxon).try(:ancestors).present?
  highest_category.taxon.ancestors_and_self.second
end

#nameObject



8
9
10
11
12
13
14
15
16
# File 'app/queries/workarea/product_primary_navigation.rb', line 8

def name
  if main_nav_taxon.present?
    main_nav_taxon.name
  elsif oldest_category.present?
    oldest_category.name
  else
    ''
  end
end

#oldest_categoryObject



30
31
32
# File 'app/queries/workarea/product_primary_navigation.rb', line 30

def oldest_category
  categories.sort { |a, b| a.created_at <=> b.created_at }.first
end