lib/aranha/parsers/html/node/default.rb in aranha-parsers-0.2.2 vs lib/aranha/parsers/html/node/default.rb in aranha-parsers-0.3.0
- old
+ new
@@ -17,15 +17,17 @@
def string_recursive_value(node, xpath, required = true)
root = node.at_xpath(xpath)
if root.blank?
return nil unless required
+
raise "No node found (Xpath: #{xpath})"
end
result = string_recursive(root)
- return result unless result.blank?
+ return result if result.present?
return nil unless required
+
raise "String blank (Xpath: #{xpath})"
end
def string_recursive_optional_value(node, xpath)
string_recursive_value(node, xpath, false)
@@ -107,9 +109,10 @@
obj.to_s.tr("\u00A0", ' ').strip
end
def string_recursive(node)
return sanitize_string(node.text) if node.is_a?(::Nokogiri::XML::Text)
+
s = ''
node.children.each do |child|
child_s = string_recursive(child)
s += ' ' + child_s if child_s.present?
end