Sha256: 44f01519062a45a8d3952a23a329914cd5d7fdc66cfc68108d979634a95ac707
Contents?: true
Size: 863 Bytes
Versions: 2
Compression:
Stored size: 863 Bytes
Contents
require "nokogiri" require_relative "bucket" module DribbbleBucketApi class BucketIndexParser attr_reader :body def initialize(body, options = {}) @body = body @options = options end def buckets @buckets ||= document.css(".bucket-list > li").map do |bucket| # parse bucket data from HTML id = bucket["class"].gsub(/^bucket\-(\d+)$/, "\1").to_i name = bucket.css(".bucket-title a").first.text # pass data into bucket object Bucket.new(id: id, name: name, username: username) end end def current_page @options[:page] || 1 end def total_entries @total_entries ||= document.css(".buckets .count").text.to_i end def total_pages (total_entries.to_f / 5).ceil end private def username @options[:username] end def document @document ||= Nokogiri::HTML(@body) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dribbble-bucket-api-0.0.2 | lib/dribbble_bucket_api/bucket_index_parser.rb |
dribbble-bucket-api-0.0.1 | lib/dribbble_bucket_api/bucket_index_parser.rb |