Class: Pixiv::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/pixiv/page.rb

Direct Known Subclasses

BookmarkList, Illust, Member

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, attrs = {}) ⇒ Page #initialize(doc_creator, attrs = {}) ⇒ Page

Returns a new instance of Page.

Overloads:

  • #initialize(doc, attrs = {}) ⇒ Page

    Parameters:

    • doc (Nokogiri::HTTP::Document)
    • attrs (Hash{Symbol=>Object}) (defaults to: {})
  • #initialize(doc_creator, attrs = {}) ⇒ Page

    Parameters:

    • doc_creator (#call)
    • attrs (Hash{Symbol=>Object}) (defaults to: {})


16
17
18
19
20
21
22
23
24
# File 'lib/pixiv/page.rb', line 16

def initialize(doc_or_doc_creator, attrs = {})
  x = doc_or_doc_creator
  if x.respond_to?(:call)
    @doc_creator = x
  else
    @doc = x
  end
  set_attrs!(attrs)
end

Class Method Details

.lazy_new(attrs = {}, &doc_creator) ⇒ Object

A new Page

Parameters:

  • attrs (Hash{Symbol=>Object}) (defaults to: {})

Yield Returns:

  • (Nokogiri::HTML::Document)


6
7
8
# File 'lib/pixiv/page.rb', line 6

def self.lazy_new(attrs = {}, &doc_creator)
  self.new(doc_creator, attrs)
end

Instance Method Details

#docNokogiri::HTTP::Document

Returns:

  • (Nokogiri::HTTP::Document)


27
28
29
30
31
32
33
# File 'lib/pixiv/page.rb', line 27

def doc
  @doc ||= begin
             doc = @doc_creator.call
             @doc_creator = nil
             doc
           end
end

#forceself

Fetch #doc and lazy attrs

Returns:

  • (self)


37
38
39
40
41
42
43
# File 'lib/pixiv/page.rb', line 37

def force
  doc
  (@@lazy_attr_readers || []).each do |reader|
    __send__(reader) if respond_to?(reader)
  end
  self
end