Class: Estatic::Category

Inherits:
Resource show all
Defined in:
lib/estatic/category.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#locals, #name

Instance Method Summary collapse

Methods inherited from Resource

#get_locals, #products_in_chunks, #proper_name, #total_chunks

Constructor Details

#initialize(name, subcategories = []) ⇒ Category



5
6
7
8
9
# File 'lib/estatic/category.rb', line 5

def initialize(name, subcategories = [])
  super(name)
  @subcategories = subcategories.map { |subcategory| Subcategory.new(subcategory, name) }
  @products = get_products
end

Instance Attribute Details

#productsObject

Returns the value of attribute products.



3
4
5
# File 'lib/estatic/category.rb', line 3

def products
  @products
end

#subcategoriesObject

Returns the value of attribute subcategories.



3
4
5
# File 'lib/estatic/category.rb', line 3

def subcategories
  @subcategories
end

Instance Method Details

#directoryObject



24
25
26
# File 'lib/estatic/category.rb', line 24

def directory
  File.join(Estatic.configuration.estatic_site_path, name)
end

#get_productsObject



15
16
17
18
19
20
21
22
# File 'lib/estatic/category.rb', line 15

def get_products
  if has_subcategories?
    subcategories.map(&:products).flatten
  else
    products = CSVParser.parse(name)
    products.map { |attributes| OpenStruct.new product(attributes) }
  end
end

#has_subcategories?Boolean



11
12
13
# File 'lib/estatic/category.rb', line 11

def has_subcategories?
  subcategories.any?
end

#root_pathObject



28
29
30
# File 'lib/estatic/category.rb', line 28

def root_path
  '../'.freeze
end