Class: Pixiv::PageCollection::Enumerator
- Inherits:
-
Object
- Object
- Pixiv::PageCollection::Enumerator
- Includes:
- Enumerable
- Defined in:
- lib/pixiv/page_collection.rb
Instance Method Summary collapse
- #each_collection ⇒ Object
- #each_page ⇒ Object (also: #each)
- #each_slice(n = nil) ⇒ Object
-
#initialize(client, collection, include_deleted_page = false) ⇒ Enumerator
constructor
A new instance of Enumerator.
- #size ⇒ Object
Constructor Details
#initialize(client, collection, include_deleted_page = false) ⇒ Enumerator
Returns a new instance of Enumerator.
51 52 53 54 55 |
# File 'lib/pixiv/page_collection.rb', line 51 def initialize(client, collection, include_deleted_page = false) @client = client @collection = collection @include_deleted_page = include_deleted_page end |
Instance Method Details
#each_collection ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/pixiv/page_collection.rb', line 86 def each_collection collection = @collection loop do yield collection next_url = collection.next_url or break next_attrs = collection.next_attrs collection = collection.class.lazy_new(next_attrs) { @client.agent.get(next_url) } end end |
#each_page ⇒ Object Also known as: each
57 58 59 60 61 62 63 64 |
# File 'lib/pixiv/page_collection.rb', line 57 def each_page each_collection do |collection| pages_from_collection(collection).each do |page| next if page.nil? && !@include_deleted_page yield page end end end |
#each_slice(n = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/pixiv/page_collection.rb', line 68 def each_slice(n = nil) if n super else if block_given? each_collection do |collection| yield pages_from_collection(collection) end else ::Enumerator.new {|y| each_slice do |slice| y << (@include_deleted_page ? slice.compact : slice) end } end end end |
#size ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/pixiv/page_collection.rb', line 96 def size if @collection.first? && @collection.respond_to?(:total_count) @collection.total_count elsif @collection.respond_to?(:max_size) && @collection.respond_to?(:total_count) @collection.total_count - (@collection.max_size * (@collection.page - 1)) else count { true } end end |