Class: SportDb::MatchReaderV2

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/readers/match_reader.rb

Overview

todo/check: rename to MatchReaderV2 (use plural?) why? why not?

Class Method Summary collapse

Class Method Details

.parse(txt) ⇒ Object



12
13
14
15
16
17
18
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
56
57
58
59
60
# File 'lib/sportdb/readers/match_reader.rb', line 12

def self.parse( txt )
  recs = LeagueOutlineReader.parse( txt )
  pp recs

  recs.each do |rec|
    league = Sync::League.find!( rec[:league] )
    season = Sync::Season.find!( rec[:season] )

    event  = Sync::Event.find!( league: league, season: season )
    if rec[:stage]
      stage = Sync::Stage.find!( rec[:stage], event: event )
      teams = stage.teams
    else
      teams = event.teams
    end

    ## hack for now: switch lang
    if ['at', 'de'].include?( league.country.key )
      SportDb.lang.lang = 'de'
      DateFormats.lang = 'de'
    elsif ['fr'].include?( league.country.key )
      SportDb.lang.lang = 'fr'
      DateFormats.lang = 'fr'
    elsif ['es'].include?( league.country.key )
      SportDb.lang.lang = 'es'
      DateFormats.lang = 'es'
    else
      SportDb.lang.lang = 'en'
      DateFormats.lang = 'en'
    end

    ## todo/fix: set lang for now depending on league country!!!
    parser = MatchParserSimpleV2.new( rec[:lines],
                              teams,  ## note: use event OR stage teams (if stage is present)
                              event.start_at )   ## note: keep season start_at date for now (no need for more specific stage date need for now)
    round_recs, match_recs = parser.parse
    pp round_recs

    round_recs.each do |round_rec|
      round = Sync::Round.find_or_create( round_rec, event: event )  ## check: use/rename to EventRound why? why not?
    end
    match_recs.each do |match_rec|
      ## todo/fix: pass along stage (if present): stage  - optional!!!!
      match = Sync::Match.create_or_update( match_rec, event: event )
    end
  end

  recs
end

.read(path) ⇒ Object

use - rename to read_file or from_file etc. - why? why not?



7
8
9
10
# File 'lib/sportdb/readers/match_reader.rb', line 7

def self.read( path )   ## use - rename to read_file or from_file etc. - why? why not?
  txt = File.open( path, 'r:utf-8' ).read
  parse( txt )
end