Class: Pixiv::Page
- Inherits:
-
Object
- Object
- Pixiv::Page
- Defined in:
- lib/pixiv/page.rb
Direct Known Subclasses
Defined Under Namespace
Modules: WithClient
Class Method Summary collapse
-
.lazy_new(attrs = {}, &doc_creator) ⇒ Object
A new Page.
Instance Method Summary collapse
-
#bind(client) ⇒ Object
private
Bind
self
toclient
. - #doc ⇒ Nokogiri::XML::Document
-
#fetched?(attr_name = :doc) ⇒ Boolean
Whether
attr_name
is fetched or not. -
#force ⇒ self
Fetch
#doc
and 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.
19 20 21 22 23 24 25 26 27 |
# File 'lib/pixiv/page.rb', line 19 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
9 10 11 |
# File 'lib/pixiv/page.rb', line 9 def self.lazy_new(attrs = {}, &doc_creator) self.new(doc_creator, attrs) end |
Instance Method Details
#bind(client) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Bind self
to client
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pixiv/page.rb', line 58 def bind(client) if self.class.const_defined?(:WithClient) mod = self.class.const_get(:WithClient) else mod = Page::WithClient end unless singleton_class.include?(mod) extend(mod) end self.client = client self end |
#doc ⇒ Nokogiri::XML::Document
37 38 39 40 41 42 43 |
# File 'lib/pixiv/page.rb', line 37 def doc @doc ||= begin doc = @doc_creator.call @doc_creator = nil doc end end |
#fetched?(attr_name = :doc) ⇒ Boolean
Whether attr_name
is fetched or not
32 33 34 |
# File 'lib/pixiv/page.rb', line 32 def fetched?(attr_name = :doc) instance_variable_defined?(:"@#{attr_name}") end |
#force ⇒ self
Fetch #doc
and lazy attrs
47 48 49 50 51 52 53 |
# File 'lib/pixiv/page.rb', line 47 def force doc (@@lazy_attr_readers || []).each do |reader| __send__(reader) if respond_to?(reader) end self end |