Class: DribbbleBucketApi::BucketIndexParser
- Inherits:
-
Object
- Object
- DribbbleBucketApi::BucketIndexParser
- Defined in:
- lib/dribbble_bucket_api/bucket_index_parser.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
- #buckets ⇒ Object
- #current_page ⇒ Object
-
#initialize(body, options = {}) ⇒ BucketIndexParser
constructor
A new instance of BucketIndexParser.
- #next_page ⇒ Object
- #previous_page ⇒ Object
- #total_entries ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(body, options = {}) ⇒ BucketIndexParser
Returns a new instance of BucketIndexParser.
8 9 10 11 |
# File 'lib/dribbble_bucket_api/bucket_index_parser.rb', line 8 def initialize(body, = {}) @body = body @options = end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/dribbble_bucket_api/bucket_index_parser.rb', line 6 def body @body end |
Instance Method Details
#buckets ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/dribbble_bucket_api/bucket_index_parser.rb', line 13 def buckets @buckets ||= document.css(".bucket-list > li").map do |bucket| # parse bucket data from HTML id = bucket["class"] =~ /^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 |
#current_page ⇒ Object
23 24 25 |
# File 'lib/dribbble_bucket_api/bucket_index_parser.rb', line 23 def current_page @options[:page] || 1 end |
#next_page ⇒ Object
27 28 29 |
# File 'lib/dribbble_bucket_api/bucket_index_parser.rb', line 27 def next_page current_page + 1 if current_page < total_pages end |
#previous_page ⇒ Object
31 32 33 |
# File 'lib/dribbble_bucket_api/bucket_index_parser.rb', line 31 def previous_page current_page - 1 if current_page > 1 end |
#total_entries ⇒ Object
35 36 37 |
# File 'lib/dribbble_bucket_api/bucket_index_parser.rb', line 35 def total_entries @total_entries ||= document.css(".buckets .count").text.to_i end |
#total_pages ⇒ Object
39 40 41 |
# File 'lib/dribbble_bucket_api/bucket_index_parser.rb', line 39 def total_pages total_entries > 0 ? (total_entries.to_f / 5).ceil : 0 end |