Class: Taobao::ProductList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/taobao/product_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ ProductList

Returns a new instance of ProductList.



5
6
7
# File 'lib/taobao/product_list.rb', line 5

def initialize(opts)
  @opts = opts
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/taobao/product_list.rb', line 36

def method_missing(method_name, *args, &block)
  if (m = /^order_by_(?<field>.+)$/.match method_name)
    order_by m[:field]
  else
    super
  end
end

Instance Method Details

#each(&block) ⇒ Object



44
45
46
# File 'lib/taobao/product_list.rb', line 44

def each(&block)
  products.each{|item| block.call(item)}
end

#order_by(field) ⇒ Object



30
31
32
33
34
# File 'lib/taobao/product_list.rb', line 30

def order_by(field)
  @products = nil
  @opts[:order_by] = field
  self
end

#page(num) ⇒ Object



18
19
20
21
22
# File 'lib/taobao/product_list.rb', line 18

def page(num)
  @products = nil
  @opts[:page_no] = num
  self
end

#per_page(num) ⇒ Object



24
25
26
27
28
# File 'lib/taobao/product_list.rb', line 24

def per_page(num)
  @products = nil
  @opts[:page_size] = num
  self
end

#sizeObject



9
10
11
# File 'lib/taobao/product_list.rb', line 9

def size
  products.size
end

#total_countObject



13
14
15
16
# File 'lib/taobao/product_list.rb', line 13

def total_count
  memoize_api_result
  @total_count
end