nakajima-elementor 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/elementor/result.rb +8 -1
- metadata +1 -1
data/lib/elementor/result.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
module Elementor
|
2
|
+
class InvalidParser < ArgumentError ; end
|
3
|
+
|
2
4
|
class Result
|
3
5
|
attr_writer :doc_ready
|
4
6
|
attr_reader :context, :opts
|
@@ -43,7 +45,12 @@ module Elementor
|
|
43
45
|
def doc(markup=nil)
|
44
46
|
if html = markup || content
|
45
47
|
@doc = nil if markup
|
46
|
-
|
48
|
+
parser = opts[:as] ? opts[:as].to_s : nil
|
49
|
+
@doc ||= case parser
|
50
|
+
when nil, 'html' then Nokogiri::HTML(html)
|
51
|
+
when 'xml' then Nokogiri::XML(html)
|
52
|
+
else raise InvalidParser.new("Nokogiri cannot parse as '#{opts[:as]}'. Please request :xml or :html.")
|
53
|
+
end
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|