Class: Estatic::Category
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
#products ⇒ Object
Returns the value of attribute products.
3
4
5
|
# File 'lib/estatic/category.rb', line 3
def products
@products
end
|
#subcategories ⇒ Object
Returns the value of attribute subcategories.
3
4
5
|
# File 'lib/estatic/category.rb', line 3
def subcategories
@subcategories
end
|
Instance Method Details
#directory ⇒ Object
24
25
26
|
# File 'lib/estatic/category.rb', line 24
def directory
File.join(Estatic.configuration.estatic_site_path, name)
end
|
#get_products ⇒ Object
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_path ⇒ Object
28
29
30
|
# File 'lib/estatic/category.rb', line 28
def root_path
'../'.freeze
end
|