Sha256: 08c40d85d6aa9b2281b5942f9faac739db8b353382472e666774118442d8befd
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
require "nokogiri" require_relative "bucket" module DribbbleBucketApi class ShotIndexParser attr_reader :body def initialize(body, options = {}) @body = body @options = options end def shots @shots ||= document.css(".dribbbles > li").map do |shot| # parse shot data from HTML id = shot["id"] =~ /^screenshot\-(\d+)$/ && $1.to_i image_teaser_url = shot.css(".dribbble-img img").first["src"] image_url = image_teaser_url.gsub(/\_teaser\.(jpe?g|png|gif)$/, '.\1') ext = image_teaser_url =~ /\.(jpe?g|png|gif)$/ && $1 url = "http://dribbble.com" + shot.css("a.dribbble-link").first["href"] # pass data into shot object Shot.new(id: id, image_teaser_url: image_teaser_url, image_url: image_url, ext: ext, url: url) end end def current_page @options[:page] || 1 end def next_page current_page + 1 if current_page < total_pages end def previous_page current_page - 1 if current_page > 1 end def total_entries @total_entries ||= (document.css("#main h2.section").text =~ /^(\d+).*$/ && $1.to_i) || 0 end def total_pages total_entries > 0 ? (total_entries.to_f / 15).ceil : 0 end private def document @document ||= Nokogiri::HTML(@body) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dribbble-bucket-api-0.0.6 | lib/dribbble_bucket_api/shot_index_parser.rb |