Class: SportDb::StatusParser
- Inherits:
-
Object
- Object
- SportDb::StatusParser
- Defined in:
- lib/sports/match_status_parser.rb
Constant Summary collapse
- RUN_RE =
/\[ (?<text>[^\]]+) \] /x
Class Method Summary collapse
Class Method Details
.find!(line) ⇒ Object
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 |
# File 'lib/sports/match_status_parser.rb', line 62 def self.find!( line ) ## for now check all "protected" text run blocks e.g. [] ## puts "line: >#{line}<" status = nil str = line while m = str.match( RUN_RE ) str = m.post_match ## keep on processing rest of line/str (a.k.a. post match string) ## check for status match match_str = m[0] ## keep a copy of the match string (for later sub) text = m[:text].strip ## puts " text: >#{text}<" status = parse( text ) if status line.sub!( match_str, "[STATUS.#{status}]" ) break end end # while match status end |
.parse(str) ⇒ Object
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/sports/match_status_parser.rb', line 29 def self.parse( str ) ## note: returns nil if no match found ## note: english usage - cancelled (in UK), canceled (in US) if str =~ /^(cancelled| canceled| can\. )/xi Status::CANCELLED elsif str =~ /^(awarded| awd\. )/xi Status::AWARDED elsif str =~ /^(postponed )/xi Status::POSTPONED elsif str =~ /^(abandoned| abd\. )/xi Status::ABANDONED elsif str =~ /^(replay )/xi Status::REPLAY else # no match nil end end |