Class: SportDb::QuickMatchOutline
- Inherits:
-
Object
- Object
- SportDb::QuickMatchOutline
- Defined in:
- lib/sportdb/parser/outline_reader.rb
Overview
add a simple Outline convenience class
for processing OUtlines with OUtlineReader
Class Method Summary collapse
Instance Method Summary collapse
- #each_para(&blk) ⇒ Object (also: #each_paragraph, #each_p)
-
#initialize(nodes) ⇒ QuickMatchOutline
constructor
A new instance of QuickMatchOutline.
Constructor Details
#initialize(nodes) ⇒ QuickMatchOutline
Returns a new instance of QuickMatchOutline.
15 16 17 |
# File 'lib/sportdb/parser/outline_reader.rb', line 15 def initialize( nodes ) @nodes = nodes end |
Class Method Details
.read(path) ⇒ Object
10 11 12 13 |
# File 'lib/sportdb/parser/outline_reader.rb', line 10 def self.read( path ) nodes = OutlineReader.read( path ) new( nodes ) end |
Instance Method Details
#each_para(&blk) ⇒ Object Also known as: each_paragraph, each_p
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sportdb/parser/outline_reader.rb', line 19 def each_para( &blk ) ## note: every (new) read call - resets errors list to empty ### @errors = [] ## process nodes h1 = nil h2 = nil orphans = 0 ## track paragraphs's with no heading @nodes.each do |node| type = node[0] if type == :h1 h1 = node[1] ## get heading text puts " = Heading 1 >#{node[1]}<" elsif type == :h2 if h1.nil? puts "!! WARN - no heading for subheading; skipping processing" next end h2 = node[1] ## get heading text puts " == Heading 2 >#{node[1]}<" elsif type == :p if h1.nil? orphans += 1 ## only warn once puts "!! WARN - no heading for #{orphans} text paragraph(s); skipping parse" next end lines = node[1] blk.call( lines ) else pp node raise ArgumentError, "unsupported (node) type >#{type}<" end end # each node end |