Class: SportDb::RaceTeamReader

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging, FixtureHelpers, Model, TextUtils::ValueHelper
Defined in:
lib/sportdb/readers/race_team.rb

Overview

squad/roster reader for races

Constant Summary

Constants included from Model

Model::City, Model::Continent, Model::Country, Model::Person, Model::Prop, Model::Region

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FixtureHelpers

#cut_off_end_of_line_comment!, #find_date!, #find_game_pos!, #find_ground!, #find_group_title_and_pos!, #find_leading_pos!, #find_person!, #find_record_comment!, #find_record_laps!, #find_record_leading_state!, #find_record_timeline!, #find_round_def_title!, #find_round_header_title!, #find_round_header_title2!, #find_round_pos!, #find_scores!, #find_team!, #find_team1!, #find_team2!, #find_teams!, #find_track!, #is_group?, #is_group_def?, #is_knockout_round?, #is_postponed?, #is_round?, #is_round_def?, #map_ground!, #map_person!, #map_team!, #map_teams!, #map_track!, #match_teams!, #match_track!

Constructor Details

#initialize(include_path, opts = {}) ⇒ RaceTeamReader

Returns a new instance of RaceTeamReader.



24
25
26
# File 'lib/sportdb/readers/race_team.rb', line 24

def initialize( include_path, opts = {} )
  @include_path = include_path
end

Instance Attribute Details

#include_pathObject (readonly)

Returns the value of attribute include_path.



21
22
23
# File 'lib/sportdb/readers/race_team.rb', line 21

def include_path
  @include_path
end

Instance Method Details

#read(name, more_attribs = {}) ⇒ 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
56
57
58
59
60
61
# File 'lib/sportdb/readers/race_team.rb', line 29

def read( name, more_attribs={} )
  ## todo: move name_real_path code to LineReaderV2 ????
  pos = name.index( '!/')
  if pos.nil?
    name_real_path = name   # not found; real path is the same as name
  else
    # cut off everything until !/ e.g.
    #   at-austria!/w-wien/beers becomes
    #   w-wien/beers
    name_real_path = name[ (pos+2)..-1 ]
  end

  path = "#{include_path}/#{name_real_path}.txt"

  logger.info "parsing data '#{name}' (#{path})..."
  ### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )

  reader = LineReader.new( path )

  ## for now: use all tracks (later filter/scope by event)
  # @known_tracks = Track.known_tracks_table

  ## fix: add @known_teams  - for now; use teams (not scoped by event)
  ## for now use all teams
  @known_teams   = TextUtils.build_title_table_for( Team.all )
  ## and for now use all persons
  @known_persons = TextUtils.build_title_table_for( Person.all )


  read_worker( reader )

  Prop.create_from_fixture!( name, path )  
end

#read_worker(reader) ⇒ Object



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
# File 'lib/sportdb/readers/race_team.rb', line 64

def read_worker( reader )

  reader.each_line do |line|
    logger.debug "  line: >#{line}<"

    cut_off_end_of_line_comment!( line )

    pos = find_leading_pos!( line )

    map_team!( line )
    team_key = find_team!( line )
    team = Team.find_by_key!( team_key )

    map_person!( line )
    person_key = find_person!( line )
    person = Person.find_by_key!( person_key )

    logger.debug "  line2: >#{line}<"

    ### check if roster record exists
    roster = Roster.find_by_event_id_and_team_id_and_person_id( @event.id, team.id, person.id )

    if roster.present?
      logger.debug "update Roster #{roster.id}:"
    else
      logger.debug "create Roster:"
      roster = Roster.new
    end

    roster_attribs = {
      pos:       pos,
      team_id:   team.id,
      person_id: person.id,
      event_id:  @event.id   # NB: reuse/fallthrough from races - make sure load_races goes first (to setup event)
    }

    logger.debug roster_attribs.to_json

    roster.update_attributes!( roster_attribs )
  end # lines.each

end