Class: Oober::Extractor::Stix
- Inherits:
-
Hashie::Dash
- Object
- Hashie::Dash
- Oober::Extractor::Stix
- Defined in:
- lib/oober/extractor/stix.rb
Instance Method Summary collapse
- #extract ⇒ Object
- #extract_selection(node) ⇒ Object
- #extract_value(node: nil, origin: nil, target: nil) ⇒ Object
- #parse_options ⇒ Object
- #selected ⇒ Object
- #xml ⇒ Object
Instance Method Details
#extract ⇒ Object
27 28 29 |
# File 'lib/oober/extractor/stix.rb', line 27 def extract selected.map {|node| extract_selection(node)} end |
#extract_selection(node) ⇒ Object
31 32 33 34 |
# File 'lib/oober/extractor/stix.rb', line 31 def extract_selection(node) mapped_values = extractions.map {|extraction| extract_value(extraction.merge(node: node)) } Hash[*mapped_values.flatten].merge(defaults) end |
#extract_value(node: nil, origin: nil, target: nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/oober/extractor/stix.rb', line 36 def extract_value(node: nil, origin: nil, target: nil) target_key = target.to_sym target_val = '' begin target_val = [*node.xpath(origin)].first.to_s.strip rescue Exception => e STDERR.puts "FAILED TO EXTRACT #{origin}" STDERR.puts e.backtrace STDERR.puts e end [target_key, target_val] end |
#parse_options ⇒ Object
23 24 25 |
# File 'lib/oober/extractor/stix.rb', line 23 def ||= Nokogiri::XML::ParseOptions::DEFAULT_XML|Nokogiri::XML::ParseOptions::NOBLANKS end |
#selected ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/oober/extractor/stix.rb', line 15 def selected @selected ||= begin xml.xpath(self.select).to_a rescue Nokogiri::XML::XPath::SyntaxError => e [] end end |
#xml ⇒ Object
11 12 13 |
# File 'lib/oober/extractor/stix.rb', line 11 def xml @xml ||= Nokogiri::XML(data,nil,nil,) end |