muffins 0.0.7.pre.2 → 0.0.7.pre.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/muffins/class_methods.rb +2 -2
- data/lib/muffins/document.rb +7 -18
- data/lib/muffins/mapping.rb +2 -2
- data/lib/muffins/version.rb +1 -1
- data/spec/muffins_spec.rb +1 -1
- metadata +1 -1
@@ -21,7 +21,7 @@ module Muffins
|
|
21
21
|
|
22
22
|
# @api public
|
23
23
|
def parse(doc, options = {})
|
24
|
-
document = Muffins::Document.new(:body => doc)
|
24
|
+
document = Muffins::Document.new(:body => doc.to_s)
|
25
25
|
|
26
26
|
if options[:single]
|
27
27
|
new_from_node(document.first(path))
|
@@ -57,4 +57,4 @@ module Muffins
|
|
57
57
|
end
|
58
58
|
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
data/lib/muffins/document.rb
CHANGED
@@ -3,16 +3,16 @@ module Muffins
|
|
3
3
|
|
4
4
|
include Virtus
|
5
5
|
|
6
|
-
attribute :body,
|
6
|
+
attribute :body, String, :reader => :protected
|
7
7
|
|
8
8
|
# @api public
|
9
9
|
def first(path)
|
10
|
-
|
10
|
+
xml.at_css(path)
|
11
11
|
end
|
12
12
|
|
13
13
|
# @api public
|
14
14
|
def all(path)
|
15
|
-
|
15
|
+
xml.css(path)
|
16
16
|
end
|
17
17
|
|
18
18
|
# @api public
|
@@ -25,21 +25,10 @@ module Muffins
|
|
25
25
|
all(path).each { |node| yield node }
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
# @api private
|
31
|
-
def body=(body)
|
32
|
-
case body
|
33
|
-
when String
|
34
|
-
@body = Nokogiri::XML(body)
|
35
|
-
when Nokogiri::XML::Element
|
36
|
-
@body = Nokogiri::XML(body.to_s)
|
37
|
-
when Nokogiri::XML::Document
|
38
|
-
@body = body
|
39
|
-
else
|
40
|
-
raise ArgumentError, "+body+ is an invalid type"
|
41
|
-
end
|
42
|
-
end
|
28
|
+
private
|
43
29
|
|
30
|
+
def xml
|
31
|
+
@xml ||= Nokogiri::XML(body)
|
32
|
+
end
|
44
33
|
end
|
45
34
|
end
|
data/lib/muffins/mapping.rb
CHANGED
@@ -10,7 +10,7 @@ module Muffins
|
|
10
10
|
|
11
11
|
# @api public
|
12
12
|
def parse(doc)
|
13
|
-
document = Muffins::Document.new(:body => doc)
|
13
|
+
document = Muffins::Document.new(:body => doc.to_s)
|
14
14
|
|
15
15
|
if collection?
|
16
16
|
document.map(absolute_path) { |node| node.text }
|
@@ -31,4 +31,4 @@ module Muffins
|
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
data/lib/muffins/version.rb
CHANGED
data/spec/muffins_spec.rb
CHANGED