Class: Elementor::Result
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#doc_ready ⇒ Object
writeonly
Sets the attribute doc_ready.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#dispatcher ⇒ Object
Returns a blank slate object that delegates to either an instance of Result or the original Nokogiri doc.
-
#doc(markup = nil) ⇒ Object
Returns the raw Nokogiri doc once a method has been called on the dispatcher.
- #doc_ready! ⇒ Object
-
#doc_ready? ⇒ Boolean
Indicates whether or not the dispatcher has received messages, meaning the content method can be called.
-
#element_names ⇒ Object
The list of name/selector pairs you specify in the elements block.
-
#initialize(context, opts = {}, &block) ⇒ Result
constructor
A new instance of Result.
-
#parse!(markup) ⇒ Object
Allows for the parsing of raw markup that doesn’t come from the :from option.
Constructor Details
#initialize(context, opts = {}, &block) ⇒ Result
Returns a new instance of Result.
6 7 8 9 10 11 12 |
# File 'lib/elementor/result.rb', line 6 def initialize(context, opts={}, &block) @opts = opts @context = context @doc_ready = false block.call(naming_context) define_elements! end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/elementor/result.rb', line 4 def context @context end |
#doc_ready=(value) ⇒ Object (writeonly)
Sets the attribute doc_ready
3 4 5 |
# File 'lib/elementor/result.rb', line 3 def doc_ready=(value) @doc_ready = value end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/elementor/result.rb', line 4 def opts @opts end |
Instance Method Details
#dispatcher ⇒ Object
Returns a blank slate object that delegates to either an instance of Result or the original Nokogiri doc.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/elementor/result.rb', line 22 def dispatcher @dispatcher ||= blank_context(:this => self) do def method_missing(sym, *args, &block) @this.doc_ready! [@this, @this.doc].each do |context| next unless context.respond_to?(sym) return context.send(sym, *args, &block) end super # raise NoMethodError if no context can handle end end end |
#doc(markup = nil) ⇒ Object
Returns the raw Nokogiri doc once a method has been called on the dispatcher. Up until that point, returns nil.
43 44 45 46 47 48 |
# File 'lib/elementor/result.rb', line 43 def doc(markup=nil) if html = markup || content @doc = nil if markup @doc ||= Nokogiri(html) end end |
#doc_ready! ⇒ Object
56 57 58 |
# File 'lib/elementor/result.rb', line 56 def doc_ready! @doc_ready = true end |
#doc_ready? ⇒ Boolean
Indicates whether or not the dispatcher has received messages, meaning the content method can be called.
52 53 54 |
# File 'lib/elementor/result.rb', line 52 def doc_ready? @doc_ready end |
#element_names ⇒ Object
The list of name/selector pairs you specify in the elements block.
37 38 39 |
# File 'lib/elementor/result.rb', line 37 def element_names @element_names ||= { } end |
#parse!(markup) ⇒ Object
Allows for the parsing of raw markup that doesn’t come from the :from option.
16 17 18 |
# File 'lib/elementor/result.rb', line 16 def parse!(markup) doc(markup) end |