Class: DribbbleBucketApi::ShotIndexParser
- Inherits:
-
Object
- Object
- DribbbleBucketApi::ShotIndexParser
- Defined in:
- lib/dribbble_bucket_api/shot_index_parser.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
- #current_page ⇒ Object
-
#initialize(body, options = {}) ⇒ ShotIndexParser
constructor
A new instance of ShotIndexParser.
- #next_page ⇒ Object
- #previous_page ⇒ Object
- #shots ⇒ Object
- #total_entries ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(body, options = {}) ⇒ ShotIndexParser
Returns a new instance of ShotIndexParser.
8 9 10 11 |
# File 'lib/dribbble_bucket_api/shot_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/shot_index_parser.rb', line 6 def body @body end |
Instance Method Details
#current_page ⇒ Object
26 27 28 |
# File 'lib/dribbble_bucket_api/shot_index_parser.rb', line 26 def current_page @options[:page] || 1 end |
#next_page ⇒ Object
30 31 32 |
# File 'lib/dribbble_bucket_api/shot_index_parser.rb', line 30 def next_page current_page + 1 if current_page < total_pages end |
#previous_page ⇒ Object
34 35 36 |
# File 'lib/dribbble_bucket_api/shot_index_parser.rb', line 34 def previous_page current_page - 1 if current_page > 1 end |
#shots ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dribbble_bucket_api/shot_index_parser.rb', line 13 def shots @shots ||= document.css(".dribbbles > li").map do |shot| # parse shot data from HTML id = shot["id"] =~ /^screenshot\-(\d+)$/ && $1.to_i = shot.css(".dribbble-img img").first["src"] image_url = .gsub(/\_teaser\.(jpe?g|png|gif)$/, '.\1') ext = =~ /\.(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_url: image_url, ext: ext, url: url) end end |
#total_entries ⇒ Object
38 39 40 |
# File 'lib/dribbble_bucket_api/shot_index_parser.rb', line 38 def total_entries @total_entries ||= (document.css("#main h2.section").text =~ /^(\d+).*$/ && $1.to_i) || 0 end |
#total_pages ⇒ Object
42 43 44 |
# File 'lib/dribbble_bucket_api/shot_index_parser.rb', line 42 def total_pages total_entries > 0 ? (total_entries.to_f / 15).ceil : 0 end |