Class: Scrubyt::ScrubytResult

Inherits:
ResultNode show all
Defined in:
lib/scrubyt/output/scrubyt_result.rb

Constant Summary

Constants inherited from ResultNode

ResultNode::OUTPUT_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from ResultNode

#generated_by_leaf, #name, #options, #result

Instance Method Summary collapse

Methods inherited from ResultNode

#has_content?, #initialize, #inspect, #to_flat_hash, #to_flat_xml, #to_hash, #to_libxml, #to_s, #to_xml, #to_xml_lines, #write_text

Constructor Details

This class inherits a constructor from Scrubyt::ResultNode

Instance Attribute Details

#root_patternsObject

Returns the value of attribute root_patterns.



3
4
5
# File 'lib/scrubyt/output/scrubyt_result.rb', line 3

def root_patterns
  @root_patterns
end

#source_fileObject

Returns the value of attribute source_file.



3
4
5
# File 'lib/scrubyt/output/scrubyt_result.rb', line 3

def source_file
  @source_file
end

#source_procObject

Returns the value of attribute source_proc.



3
4
5
# File 'lib/scrubyt/output/scrubyt_result.rb', line 3

def source_proc
  @source_proc
end

Instance Method Details

#exportObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/scrubyt/output/scrubyt_result.rb', line 5

def export
  #Temporary solution; the real one will be back later - or not     
 result = <<-EXPLANATION
 
 === Extractor tree ===
 
 export() is not working at the moment, due to the removal or ParseTree, ruby2ruby and RubyInline.
 For now, in case you are using examples, you can replace them by hand based on the output below.
 So if your pattern in the learning extractor looks like
 
 book "Ruby Cookbook" 
 
 and you see the following below:
 
 [book] /table[1]/tr/td[2]
 
 then replace "Ruby Cookbook" with "/table[1]/tr/td[2]" (and all the other XPaths) and you are ready!
 
 EXPLANATION
 
 tree_builder = lambda do |node, level|        
   result += current_level = ("   " * (level == 0 ? 0 : level-1) + 
                              "|\n" * (level == 0 ? 0 : 1) +
                              "   " * (level == 0 ? 0 : level-1) + 
                             "+-- " * (level == 0 ? 0 : 1) + 
                             "[#{node.name}]")
   result += " #{node.filters[0].xpath}" if node.type == :tree
   result += "\n"                                 
                             
   node.children.each {|c| tree_builder[c, level+1]}
 end
 
 tree_builder[root_patterns[0],0]
      
 result += "\n"
end