Class: Taobao::Category

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/taobao/category.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#to_object

Constructor Details

#initialize(category_id) ⇒ Category

Returns a new instance of Category.

Parameters:

  • category_id (Integer)


6
7
8
# File 'lib/taobao/category.rb', line 6

def initialize(category_id)
  @id = category_id.to_i
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Instance Method Details

#nameString

Returns:

  • (String)


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

def name
  @name ||= category_request(cids: @id)[:name]
end

#productsTaobao::ProductList

Returns:



31
32
33
# File 'lib/taobao/category.rb', line 31

def products
  @products ||= Taobao::ProductList.new(cid: @id)
end

#propertiesTaobao::PropertyList



26
27
28
# File 'lib/taobao/category.rb', line 26

def properties
  @properties ||= Taobao::PropertyList.new(cid: @id)
end

#subcategoriesArray<Taobao::Category>

Returns:



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

def subcategories
  return @subcategories if @subcategories
  @subcategories = category_request(parent_cid: @id).map do |cat|
    category = self.class.new cat[:cid]
    category.to_object(cat)
    category
  end
end