Class: SportDb::RosterReader

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

Constant Summary

Constants included from Model

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FixtureHelpers

#calculate_year, #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 = {}) ⇒ RosterReader

Returns a new instance of RosterReader.



23
24
25
# File 'lib/sportdb/readers/roster.rb', line 23

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

Instance Attribute Details

#include_pathObject (readonly)

Returns the value of attribute include_path.



20
21
22
# File 'lib/sportdb/readers/roster.rb', line 20

def include_path
  @include_path
end

Instance Method Details

#read(name, more_attribs = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sportdb/readers/roster.rb', line 28

def read( name, more_attribs={} )
  path = "#{include_path}/#{name}.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_rosters_worker( reader )

  Prop.create_from_fixture!( name, path )  
end

#read_rosters_worker(reader) ⇒ Object



53
54
55
56
57
58
59
60
61
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
87
88
89
90
91
92
93
94
# File 'lib/sportdb/readers/roster.rb', line 53

def read_rosters_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