Class: MMonitor::Strategies::Yhd

Inherits:
Parser
  • Object
show all
Defined in:
lib/mmonitor/strategies/yhd.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#extra, #get_html, #list, #page_key, #price, #price_url, #process, #sku_id, #tag_price, #title, #total

Constructor Details

#initialize(dom, url) ⇒ Yhd

Returns a new instance of Yhd.



10
11
12
13
14
15
16
17
18
19
# File 'lib/mmonitor/strategies/yhd.rb', line 10

def initialize(dom, url)
  self.body = dom.at(css_path[:body])
  self.items ||= {}
  self.url = url.sub('s2', 'searchPage')
  self.pages_count = self.body.at(css_path[:pages]).text.split('/')[1].to_i
  self.page = 1
  process
  get_ajax(true)
  next_page
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



8
9
10
# File 'lib/mmonitor/strategies/yhd.rb', line 8

def body
  @body
end

#itemObject

Returns the value of attribute item.



8
9
10
# File 'lib/mmonitor/strategies/yhd.rb', line 8

def item
  @item
end

#itemsObject

Returns the value of attribute items.



8
9
10
# File 'lib/mmonitor/strategies/yhd.rb', line 8

def items
  @items
end

#pageObject

Returns the value of attribute page.



8
9
10
# File 'lib/mmonitor/strategies/yhd.rb', line 8

def page
  @page
end

#pages_countObject

Returns the value of attribute pages_count.



8
9
10
# File 'lib/mmonitor/strategies/yhd.rb', line 8

def pages_count
  @pages_count
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/mmonitor/strategies/yhd.rb', line 8

def url
  @url
end

Instance Method Details

#css_pathObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mmonitor/strategies/yhd.rb', line 26

def css_path
  {
    body:      '#plist',
    list:      '#itemSearchList',
    item:      'li.search_item > div.search_item_box',
    pages:     '#rankOpDiv > div > div.select_page_num', # .text.split('/')[1]
    spu_id:    'pmid',
    title:     'p.title > a',
    photo_url: 'a.search_prod_img > img', # 'data-ks-lazyload'
    price:     'div.pricebox.clearfix  > span:nth-child(1)'
  }
end

#pagesObject

分页伪装



49
50
51
# File 'lib/mmonitor/strategies/yhd.rb', line 49

def pages
  1
end

#photo_urlObject

产品图片



43
44
45
46
# File 'lib/mmonitor/strategies/yhd.rb', line 43

def photo_url # 产品图片
  img = self.item.at(css_path[:photo_url])
  img['original'] || img['src']
end

#providerObject

输出的产品



22
23
24
# File 'lib/mmonitor/strategies/yhd.rb', line 22

def provider
  :yhd
end

#spu_idObject

产品图片



39
40
41
# File 'lib/mmonitor/strategies/yhd.rb', line 39

def spu_id # 产品图片
  self.item.at(css_path[:title])[css_path[:spu_id]]
end