Module: ScoreFormats

Defined in:
lib/score-formats.rb,
lib/score-formats.rb,
lib/score-formats/parser.rb,
lib/score-formats/formats.rb,
lib/score-formats/version.rb

Overview

todo/fix: make logging class configurable - lets you use logutils etc.

Defined Under Namespace

Modules: Logging Classes: ScoreParser

Constant Summary collapse

P_EN =

english helpers (penalty, extra time, …)

'(?: p | pen\.? | pso )'
ET_EN =

e.g. p, pen, pen., PSO, etc.

'(?: aet | a\.e\.t\.? )'
EN__P_ET__RE =

note: allow SPECIAL cases WITHOUT full time scores (just a.e.t or pen. + a.e.t.)

3-4 pen. 2-2 a.e.t.
         2-2 a.e.t.
/\b
            (?:
(?<score1p>\d{1,2})
  [ ]* - [ ]*          # note: sep in optional block; CANNOT use a reference
(?<score2p>\d{1,2})
  [ ]* #{P_EN} [ ]*
             )?            # note: make penalty (P) score optional for now
            (?<score1et>\d{1,2})
[ ]* - [ ]*
            (?<score2et>\d{1,2})
[ ]* #{ET_EN}
(?=[ \]]|$)/xi
EN__P_ET_FT_HT__RE =

e.g. 3-4 pen. 2-2 a.e.t. (1-1, 1-1) or

3-4 pen. 2-2 a.e.t. (1-1, )     or
3-4 pen. 2-2 a.e.t. (1-1)       or
         2-2 a.e.t. (1-1, 1-1)  or
         2-2 a.e.t. (1-1, )     or
         2-2 a.e.t. (1-1)
/\b
  (?:
   (?<score1p>\d{1,2})
      [ ]* - [ ]*          # note: sep in optional block; CANNOT use a reference
   (?<score2p>\d{1,2})
      [ ]* #{P_EN} [ ]*
   )?            # note: make penalty (P) score optional for now
  (?<score1et>\d{1,2})
      [ ]* - [ ]*
  (?<score2et>\d{1,2})
      [ ]* #{ET_EN} [ ]*
      \(
      [ ]*
 (?<score1>\d{1,2})
      [ ]* - [ ]*
 (?<score2>\d{1,2})
      [ ]*
   (?:
        , [ ]*
       (?: (?<score1i>\d{1,2})
           [ ]* - [ ]*
           (?<score2i>\d{1,2})
           [ ]*
       )?
   )?              # note: make half time (HT) score optional for now
 \)
(?=[ \]]|$)/xi
EN__P_FT_HT__RE =

special case for case WITHOUT extra time!!

same as above (but WITHOUT extra time and pen required)
/\b
   (?<score1p>\d{1,2})
      [ ]* - [ ]*          # note: sep in optional block; CANNOT use a reference
   (?<score2p>\d{1,2})
      [ ]* #{P_EN} [ ]*
      \(
      [ ]*
 (?<score1>\d{1,2})
      [ ]* - [ ]*
 (?<score2>\d{1,2})
      [ ]*
   (?:
        , [ ]*
       (?: (?<score1i>\d{1,2})
           [ ]* - [ ]*
           (?<score2i>\d{1,2})
           [ ]*
       )?
   )?              # note: make half time (HT) score optional for now
 \)
(?=[ \]]|$)/xi
EN__FT_HT__RE =

e.g. 2-1 (1-1) or

2-1

note: for now add here used in Brazil / Portugal

e.g 1x1 or 1X1 or 0x2 or 3x3  too
 todo/check/fix: move to its own use PT__FT_HT etc!!!!
/\b
 (?<score1>\d{1,2})
   [ ]* (?<sep>[x-]) [ ]*
 (?<score2>\d{1,2})
  (?:
      [ ]* \( [ ]*
   (?<score1i>\d{1,2})
      [ ]* \k<sep> [ ]*
   (?<score2i>\d{1,2})
      [ ]* \)
  )?   # note: make half time (HT) score optional for now
(?=[ \]]|$)/xi
P_DE =

deutsch / german helpers (penalty, extra time, …) todo add more marker e.g. im Elf. or such!!!

'(?: ie | i\.e\.? )'
ET_DE =

e.g. iE, i.E., i.E etc.

'(?: nv | n\.v\.? )'
DE__P_ET_FT_HT__RE =

support alternate all-in-one score e.g.

i.E. 2:4, n.V. 3:3 (1:1, 1:1)  or
          n.V. 3:2 (2:2, 1:2)
/\b
       (?:
       #{P_DE}
        [ ]*
       (?<score1p>\d{1,2})
        [ ]* : [ ]*
       (?<score2p>\d{1,2})
        [ ]* (?:, [ ]*)?
       )?   # note: make penalty (P) score optional for now
        #{ET_DE}
        [ ]*
       (?<score1et>\d{1,2})
        [ ]* : [ ]*
       (?<score2et>\d{1,2})
        [ ]*
      \(
   [ ]*
             (?<score1>\d{1,2})
    [ ]* : [ ]*
             (?<score2>\d{1,2})
    [ ]*
 (?:
     , [ ]*
     (?:
      (?<score1i>\d{1,2})
        [ ]* : [ ]*
      (?<score2i>\d{1,2})
        [ ]*
     )?
 )?    # note: make half time (HT) score optional for now
             \)
            (?=[ \]]|$)
/xi
DE__ET_FT_HT_P__RE =

support all-in-one “literal form e.g.

2:2 (1:1, 1:0) n.V. 5:1 i.E.   or
2-2 (1-1, 1-0) n.V. 5-1 i.E.
/\b
(?<score1et>\d{1,2})
    [ ]* (?<sep>[:-]) [ ]*     ## note: for now allow : or - as separator!!
(?<score2et>\d{1,2})
    [ ]*
    \(
   [ ]*
              (?<score1>\d{1,2})
    [ ]* \k<sep> [ ]*
              (?<score2>\d{1,2})
    [ ]*
 (?:
     , [ ]*
     (?:
      (?<score1i>\d{1,2})
        [ ]* \k<sep> [ ]*
      (?<score2i>\d{1,2})
        [ ]*
     )?
 )?    # note: make half time (HT) score optional for now
              \)
[ ]*
#{ET_DE}
              (?:
 [ ]*
 (?<score1p>\d{1,2})
  [ ]* \k<sep> [ ]*
 (?<score2p>\d{1,2})
   [ ]*
 #{P_DE}
              )?       # note: make penalty (P) score optional for now
             (?=[ \]]|$)
/xi
DE__FT_HT__RE =

e.g. 2:1 (1:1) or

2-1 (1-1)  or
2:1        or
2-1
/\b
 (?<score1>\d{1,2})
   [ ]* (?<sep>[:-]) [ ]*
 (?<score2>\d{1,2})
  (?:
     [ ]* \( [ ]*
         (?<score1i>\d{1,2})
           [ ]* \k<sep> [ ]*
         (?<score2i>\d{1,2})
     [ ]* \)
  )?   # note: make half time (HT) score optional for now
(?=[ \]]|$)/x
FORMATS_EN =
[
  [ EN__P_ET_FT_HT__RE, '[SCORE.EN__P?_ET_(FT_HT?)]' ], # e.g. 5-1 pen. 2-2 a.e.t. (1-1, 1-0)

  [ EN__P_FT_HT__RE,    '[SCORE.EN__P_(FT_HT?)]'     ], # e.g. 5-1 pen. (1-1)

  [ EN__P_ET__RE,       '[SCORE.EN__P?_ET]'          ], # e.g. 2-2 a.e.t.  or  5-1 pen. 2-2 a.e.t.

  [ EN__FT_HT__RE,      '[SCORE.EN__FT_(HT)?]'       ], # e.g. 1-1 (1-0)

]
FORMATS_DE =
[
  [ DE__ET_FT_HT_P__RE, '[SCORE.DE__ET_(FT_HT?)_P?]' ], # e.g. 2:2 (1:1, 1:0) n.V. 5:1 i.E.

  [ DE__P_ET_FT_HT__RE, '[SCORE.DE__P?_ET_(FT_HT?)]' ], # e.g. i.E. 2:4, n.V. 3:3 (1:1, 1:1)

  [ DE__FT_HT__RE,      '[SCORE.DE__FT_(HT)?]'       ], # e.g. 1:1 (1:0)

]
FORMATS =
{
  en: FORMATS_EN,
  de: FORMATS_DE,
}
MAJOR =

todo: namespace inside version or something - why? why not??

0
MINOR =
0
PATCH =
1
VERSION =
[MAJOR,MINOR,PATCH].join('.')

Class Method Summary collapse

Class Method Details



12
13
14
# File 'lib/score-formats/version.rb', line 12

def self.banner
  "score-formats/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
end

.find!(line, lang: ScoreFormats.lang) ⇒ Object



50
51
52
# File 'lib/score-formats.rb', line 50

def self.find!( line, lang: ScoreFormats.lang )
  parser( lang: lang ).find!( line )
end

.langObject



30
31
32
# File 'lib/score-formats.rb', line 30

def self.lang
  @@lang ||= :en            ## defaults to english (:en)
end

.lang=(value) ⇒ Object



33
34
35
36
# File 'lib/score-formats.rb', line 33

def self.lang=( value )
  @@lang = value.to_sym    ## note: make sure lang is always a symbol for now (NOT a string)
  @@lang      ## todo/check: remove  =() method always returns passed in value? double check
end

.parse(line, lang: ScoreFormats.lang) ⇒ Object



46
47
48
# File 'lib/score-formats.rb', line 46

def self.parse( line, lang: ScoreFormats.lang )
  parser( lang: lang ).parse( line )
end

.parser(lang:) ⇒ Object

find parser



38
39
40
41
42
43
44
# File 'lib/score-formats.rb', line 38

def self.parser( lang: )  ## find parser
  lang = lang.to_sym  ## note: make sure lang is always a symbol for now (NOT a string)

  ## note: cache all "built-in" lang versions (e.g. formats == nil)
  @@parser ||= {}
  parser = @@parser[ lang ] ||= ScoreParser.new( lang: lang )
end

.rootObject



16
17
18
# File 'lib/score-formats/version.rb', line 16

def self.root
  File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end

.versionObject



8
9
10
# File 'lib/score-formats/version.rb', line 8

def self.version
  VERSION
end