Module: Peekapp::Ratings
- Defined in:
- lib/peekapp/ratings.rb
Class Method Summary collapse
Class Method Details
.from_app(id, stores, options = {}) ⇒ Object
{{{
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/peekapp/ratings.rb', line 5 def self.from_app id, stores, = {} # {{{ = Array.new stores.each do |s| << parse({ :dom => Peekapp::query({ :url => $peekapp_config[:ratings_url], :page => 1, :app_id => id, :store_id => s, :app_version => ([:app_version] ? [:app_version] : "all") }), :store_id => s }) end end |
.parse(data) ⇒ Object
}}}
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/peekapp/ratings.rb', line 22 def self.parse data # {{{ = Rating.new :store_id => data[:store_id] dom = Nokogiri::HTML.parse(data[:dom]) = dom.css("div.ratings-histogram").count dom.css("div.ratings-histogram").each_with_index do |r,i| data = Hash.new result = true r.css("div.vote").each_with_index{ |v,j| data.merge!({(5-j) => v.css("span.total").children.to_s.to_i }) } if === 1 or i === 1 .set :key => :all, :value => data .set :key => :current, :value => data if === 1 else .set :key => :current, :value => data end end .set :key => :all, :value => {1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0} if < 1 end |