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
Bind
self
toclient
. - #doc ⇒ Nokogiri::HTTP::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.
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
#bind(client) ⇒ Object
Bind self
to client
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pixiv/page.rb', line 54 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::HTTP::Document
34 35 36 37 38 39 40 |
# File 'lib/pixiv/page.rb', line 34 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
29 30 31 |
# File 'lib/pixiv/page.rb', line 29 def fetched?(attr_name = :doc) instance_variable_get(:"@#{attr_name}") != nil end |
#force ⇒ self
Fetch #doc
and lazy attrs
44 45 46 47 48 49 50 |
# File 'lib/pixiv/page.rb', line 44 def force doc (@@lazy_attr_readers || []).each do |reader| __send__(reader) if respond_to?(reader) end self end |