Class: Taobao::ProductList

Inherits:
AbstractList show all
Defined in:
lib/taobao/product_list.rb

Instance Method Summary collapse

Methods inherited from AbstractList

#initialize

Constructor Details

This class inherits a constructor from Taobao::AbstractList

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



25
26
27
28
29
30
31
# File 'lib/taobao/product_list.rb', line 25

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



33
34
35
# File 'lib/taobao/product_list.rb', line 33

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

#order_by(field) ⇒ Object



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

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

#page(num) ⇒ Object



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

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

#per_page(num) ⇒ Object



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

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

#sizeObject



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

def size
  products.size
end

#total_countObject



37
38
39
# File 'lib/taobao/product_list.rb', line 37

def total_count
  cached_responce[:items_get_response][:total_results].to_i
end