Class: SportDb::Parser::Linter
- Inherits:
-
Object
- Object
- SportDb::Parser::Linter
- Defined in:
- lib/sportdb/parser/linter.rb
Overview
note - Linter for now nested inside Parser - keep? why? why not?
Constant Summary collapse
- ATTRIB_RE =
note: colon (:) MUST be followed by one (or more) spaces
make sure mon feb 12 18:10 will not match allow 1. FC Köln etc. Mainz 05: limit to 30 chars max only allow chars incl. intl buut (NOT ()[]/;) Group A: Group B: - remove colon or lookup first
%r{^ [ ]*? # slurp leading spaces (?<key>[^:|\]\[()\/; -] [^:|\]\[()\/;]{0,30} ) [ ]*? # slurp trailing spaces :[ ]+ (?<value>.+) [ ]*? # slurp trailing spaces $ }ix
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
- .debug=(value) ⇒ Object
-
.debug? ⇒ Boolean
note: default is FALSE.
Instance Method Summary collapse
- #debug? ⇒ Boolean
- #errors? ⇒ Boolean
-
#initialize ⇒ Linter
constructor
A new instance of Linter.
-
#read(path, parse: false) ⇒ Object
parse - false (default) - tokenize (only) - true - tokenize & parse.
Constructor Details
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
15 16 17 |
# File 'lib/sportdb/parser/linter.rb', line 15 def errors @errors end |
Class Method Details
.debug=(value) ⇒ Object
9 |
# File 'lib/sportdb/parser/linter.rb', line 9 def self.debug=(value) @@debug = value; end |
.debug? ⇒ Boolean
note: default is FALSE
10 |
# File 'lib/sportdb/parser/linter.rb', line 10 def self.debug?() @@debug ||= false; end |
Instance Method Details
#debug? ⇒ Boolean
11 |
# File 'lib/sportdb/parser/linter.rb', line 11 def debug?() self.class.debug?; end |
#errors? ⇒ Boolean
23 |
# File 'lib/sportdb/parser/linter.rb', line 23 def errors?() @errors.size > 0; end |
#read(path, parse: false) ⇒ Object
parse - false (default) - tokenize (only)
- true - tokenize & parse
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/sportdb/parser/linter.rb', line 54 def read( path, parse: false ) ## note: every (new) read call - resets errors list to empty @errors = [] nodes = OutlineReader.read( path ) ## process nodes h1 = nil h2 = nil orphans = 0 ## track paragraphs's with no heading attrib_found = false 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 parse" 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] tree = [] lines.each_with_index do |line,i| if debug? puts puts "line >#{line}<" end ## skip new (experimental attrib syntax) if attrib_found == false && ATTRIB_RE.match?( line ) ## note: check attrib regex AFTER group def e.g.: ## Group A: ## Group B: etc. ## todo/fix - change Group A: to Group A etc. ## Group B: to Group B attrib_found = true ## logger.debug "skipping key/value line - >#{line}<" next end if attrib_found ## check if line ends with dot ## if not slurp up lines to the next do!!! ## logger.debug "skipping key/value line - >#{line}<" attrib_found = false if line.end_with?( '.' ) # logger.debug "skipping key/value line (cont.) - >#{line}<" next end t, = if parse @parser.parse_with_errors( line ) else @parser.tokenize_with_errors( line ) end if .size > 0 ## add to "global" error list ## make a triplet tuple (file / msg / line text) .each do |msg| @errors << [ path, msg, line ] end end pp t if debug? tree << t end ## pp tree else pp node raise ArgumentError, "unsupported (node) type >#{type}<" end end # each node end |