Class: Workarea::ProductPrimaryNavigation
- Inherits:
-
Object
- Object
- Workarea::ProductPrimaryNavigation
- Defined in:
- app/queries/workarea/product_primary_navigation.rb
Instance Method Summary collapse
- #highest_category ⇒ Object
-
#initialize(product, options = {}) ⇒ ProductPrimaryNavigation
constructor
A new instance of ProductPrimaryNavigation.
- #main_nav_taxon ⇒ Object
- #name ⇒ Object
- #oldest_category ⇒ Object
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, = {}) @product = product @options = end |
Instance Method Details
#highest_category ⇒ Object
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 |
#main_nav_taxon ⇒ Object
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 |
#name ⇒ Object
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_category ⇒ Object
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 |