Class: Pixiv::Page
- Inherits:
-
Object
- Object
- Pixiv::Page
- Defined in:
- lib/pixiv/page.rb
Direct Known Subclasses
Class Method Summary collapse
-
.lazy_new(attrs = {}, &doc_creator) ⇒ Object
A new Page.
Instance Method Summary collapse
- #doc ⇒ Nokogiri::HTTP::Document
-
#force ⇒ self
Fetch
#docand lazy attrs. -
#initialize(doc_or_doc_creator, attrs = {}) ⇒ Page
constructor
A new instance of Page.
Constructor Details
#initialize(doc, attrs = {}) ⇒ Page #initialize(doc_creator, attrs = {}) ⇒ Page
Returns a new instance of Page.
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
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
#doc ⇒ 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 |
#force ⇒ self
Fetch #doc and lazy attrs
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 |