Class: ESpider::Front::Baidu::Map::Hotel::Detail

Inherits:
Object
  • Object
show all
Defined in:
lib/espider/front/baidu/map/hotel/detail.rb

Constant Summary collapse

HotelUri =
"http://map.baidu.com/detail"

Instance Method Summary collapse

Constructor Details

#initialize(uid) ⇒ Detail

Returns a new instance of Detail.



11
12
13
14
15
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 11

def initialize(uid)
  url = HotelUri + "?qt=ninf&uid=#{uid}"
  @hotel = JSON.parse HTTParty.get url
  true
end

Instance Method Details

#hotel_addrObject



19
20
21
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 19

def hotel_addr
  @hotel['content']['addr']
end

#hotel_categoryObject



31
32
33
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 31

def hotel_category
  @hotel['content']['ext']['rich_info']['category']
end

#hotel_facilityObject



37
38
39
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 37

def hotel_facility
  @hotel['content']['ext']['rich_info']['inner_facility']
end

#hotel_geoObject



25
26
27
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 25

def hotel_geo
  @hotel['content']['geo'].split(/;/)[0].sub(/\d+\|/,"").split(',')
end

#hotel_image(uid) ⇒ Object



50
51
52
53
54
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 50

def hotel_image(uid)
  url = HotelUri + "?qt=img&uid=#{uid}"
  parsed_json = JSON.parse HTTParty.get url
  parsed_json['images'].map{ |i| i['imgUrl']}
end

#hotel_nameObject



16
17
18
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 16

def hotel_name
  @hotel['content']['name']
end

#hotel_priceObject



34
35
36
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 34

def hotel_price
  @hotel['content']['ext']['detail_info']['price']
end

#hotel_reviewObject



43
44
45
46
47
48
49
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 43

def hotel_review
  reviews = []
  @hotel['content']['ext']['review'].each do |r|
    reviews << r if r['name']!='elong'
  end
  reviews
end

#hotel_short_commObject



40
41
42
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 40

def hotel_short_comm
  @hotel['content']['ext']['detail_info']['short_comm']
end

#hotel_starObject



28
29
30
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 28

def hotel_star
  @hotel['content']['ext']['rich_info']['level']
end

#hotel_telObject



22
23
24
# File 'lib/espider/front/baidu/map/hotel/detail.rb', line 22

def hotel_tel
  @hotel['content']['phone']
end