Class: Daodao::RankFast
- Inherits:
-
Object
- Object
- Daodao::RankFast
- Defined in:
- lib/daodao/rank_fast.rb
Constant Summary collapse
- Host =
'www.daodao.com'- Options =
{ :headers => headers }
Instance Method Summary collapse
- #html ⇒ Object
-
#initialize ⇒ RankFast
constructor
A new instance of RankFast.
- #rank(hotel_id) ⇒ Object
Constructor Details
#initialize ⇒ RankFast
Returns a new instance of RankFast.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/daodao/rank_fast.rb', line 9 def initialize @date = Date.today @inMonth = "#{@date.month}/#{@date.year}" @outMonth = @inMonth @inDay = @date.day @outDay = @inDay + 1 @params = { :inMonth => @inMonth, :inDay => @inDay, :outMonth => @outMonth, :outDay => @outDay, :area => 'QC_Meta_Mini', :adults => 2, :returnAllOffers => true } end |
Instance Method Details
#html ⇒ Object
49 50 51 |
# File 'lib/daodao/rank_fast.rb', line 49 def html @html.to_html end |
#rank(hotel_id) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/daodao/rank_fast.rb', line 26 def rank(hotel_id) hotel_id = hotel_id[/\d+/] q = Array.new q << "detail=#{hotel_id}" # Join arguments @params.each do |k, v| q << "#{k.to_s}=#{v.to_s}" end uri = URI::HTTP.build(:host=>Host,:path=>'/MiniMetaCRAjax',:query=>q.join('&')) @html = Nokogiri::HTML(HTTParty.get(uri, Options)) row = {} row[:hotel_id] = hotel_id provider = @html.css("*.no_cpu.offer") rank = 1 #row[:hotel_name] = @html.search("//h1[@id='HEADING']/text()").to_s.gsub(/\n|\s/,'') provider.each { |item| key = 'rank'+rank.to_s row[key.to_sym] = item['data-vendorname'] rank+=1 } row end |