Class: SportDb::MatchParser
- Inherits:
-
Object
- Object
- SportDb::MatchParser
- Includes:
- LogUtils::Logging
- Defined in:
- lib/sportdb/quick/match_parser.rb
Overview
simple match parser for team match schedules
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.
- .parse(txt, start:) ⇒ Object
Instance Method Summary collapse
- #debug? ⇒ Boolean
- #errors? ⇒ Boolean
-
#initialize(txt, start:) ⇒ MatchParser
constructor
A new instance of MatchParser.
- #parse ⇒ Object
Constructor Details
#initialize(txt, start:) ⇒ MatchParser
Returns a new instance of MatchParser.
19 20 21 22 23 24 |
# File 'lib/sportdb/quick/match_parser.rb', line 19 def initialize( txt, start: ) @txt = txt @start = start @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
27 28 29 |
# File 'lib/sportdb/quick/match_parser.rb', line 27 def errors @errors end |
Class Method Details
.debug=(value) ⇒ Object
5 |
# File 'lib/sportdb/quick/match_parser.rb', line 5 def self.debug=(value) @@debug = value; end |
.debug? ⇒ Boolean
note: default is FALSE
6 |
# File 'lib/sportdb/quick/match_parser.rb', line 6 def self.debug?() @@debug ||= false; end |
.parse(txt, start:) ⇒ Object
13 14 15 16 17 |
# File 'lib/sportdb/quick/match_parser.rb', line 13 def self.parse( txt, start: ) ## todo/check - add teams: option like start: why? why not? parser = new( txt, start: start ) parser.parse end |
Instance Method Details
#debug? ⇒ Boolean
7 |
# File 'lib/sportdb/quick/match_parser.rb', line 7 def debug?() self.class.debug?; end |
#errors? ⇒ Boolean
28 |
# File 'lib/sportdb/quick/match_parser.rb', line 28 def errors?() @errors.size > 0; end |
#parse ⇒ Object
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sportdb/quick/match_parser.rb', line 30 def parse ## note: every (new) read call - resets errors list to empty @errors = [] @warns = [] ## track list of warnings (unmatched lines) too - why? why not? if debug? puts "lines:" pp @txt end =begin t, error_messages = @parser.parse_with_errors( line ) if error_messages.size > 0 ## add to "global" error list ## make a triplet tuple (file / msg / line text) error_messages.each do |msg| @errors << [ '<file>', ## add filename here msg, line ] end end pp t if debug? @tree << t =end parser = RaccMatchParser.new( @txt ) ## use own parser instance (not shared) - why? why not? tree = parser.parse ## pp @tree ## report parse errors here - why? why not? ## note - team keys are names and values are "internal" stats e.g. usage count!! ## and NOT team/club/nat_team structs!! ## returns [@teams.keys, @matches, @rounds.values, @groups.values] conv = MatchTree.new( tree, start: @start ) conv.convert end |