Module: Aranha::Parsers::Html::Node::Default::StringSupport
- Defined in:
- lib/aranha/parsers/html/node/default/string_support.rb
Instance Method Summary collapse
- #quoted_value(node, xpath) ⇒ Object
- #regxep(node, xpath, pattern) ⇒ Object
- #string_recursive_optional_value(node, xpath) ⇒ Object
-
#string_recursive_value(node, xpath, required = true) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter.
- #string_value(node, xpath) ⇒ String
Instance Method Details
#quoted_value(node, xpath) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/aranha/parsers/html/node/default/string_support.rb', line 12 def quoted_value(node, xpath) s = string_value(node, xpath) return '' unless s m = /"([^\"]+)"/.match(s) return m[1] if m '' end |
#regxep(node, xpath, pattern) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/aranha/parsers/html/node/default/string_support.rb', line 22 def regxep(node, xpath, pattern) s = string_value(node, xpath) m = pattern.match(s) return m if m raise "Pattern \"#{pattern}\" not found in string \"#{s}\"" end |
#string_recursive_optional_value(node, xpath) ⇒ Object
52 53 54 |
# File 'lib/aranha/parsers/html/node/default/string_support.rb', line 52 def string_recursive_optional_value(node, xpath) string_recursive_value(node, xpath, false) end |
#string_recursive_value(node, xpath, required = true) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/aranha/parsers/html/node/default/string_support.rb', line 38 def string_recursive_value(node, xpath, required = true) # rubocop:disable Style/OptionalBooleanParameter root = node_value(node, xpath) if root.blank? return nil unless required raise "No node found (Xpath: #{xpath})" end result = string_recursive(root) return result if result.present? return nil unless required raise "String blank (Xpath: #{xpath})" end |
#string_value(node, xpath) ⇒ String
33 34 35 36 |
# File 'lib/aranha/parsers/html/node/default/string_support.rb', line 33 def string_value(node, xpath) found = node_value(node, xpath) found ? sanitize_string(found.text) : '' end |