Class: SportDb::RecordReader
- Inherits:
-
Object
- Object
- SportDb::RecordReader
- Includes:
- LogUtils::Logging, FixtureHelpers, Model, TextUtils::ValueHelper
- Defined in:
- lib/sportdb/readers/record.rb
Constant Summary
Constants included from Model
Model::City, Model::Continent, Model::Country, Model::Prop, Model::Region
Instance Attribute Summary collapse
-
#include_path ⇒ Object
readonly
Returns the value of attribute include_path.
Instance Method Summary collapse
-
#initialize(include_path, opts = {}) ⇒ RecordReader
constructor
A new instance of RecordReader.
- #read(name, more_attribs = {}) ⇒ Object
- #read_records_worker(reader, more_attribs) ⇒ Object
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 = {}) ⇒ RecordReader
Returns a new instance of RecordReader.
23 24 25 |
# File 'lib/sportdb/readers/record.rb', line 23 def initialize( include_path, opts = {} ) @include_path = include_path end |
Instance Attribute Details
#include_path ⇒ Object (readonly)
Returns the value of attribute include_path.
20 21 22 |
# File 'lib/sportdb/readers/record.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 |
# File 'lib/sportdb/readers/record.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) @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_records_worker( reader, more_attribs ) Prop.create_from_fixture!( name, path ) end |
#read_records_worker(reader, more_attribs) ⇒ Object
51 52 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 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/sportdb/readers/record.rb', line 51 def read_records_worker( reader, more_attribs ) reader.each_line do |line| logger.debug " line: >#{line}<" cut_off_end_of_line_comment!( line ) state = find_record_leading_state!( 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 ) timeline = find_record_timeline!( line ) laps = find_record_laps!( line ) comment = find_record_comment!( line ) logger.debug " line2: >#{line}<" record_attribs = { state: state, ## team_id: team.id, ## NB: not needed for db person_id: person.id, timeline: timeline, comment: comment, laps: laps } record_attribs = record_attribs.merge( more_attribs ) ### check if record exists record = Record.find_by_race_id_and_person_id( record_attribs[ :race_id ], record_attribs[ :person_id ]) if record.present? logger.debug "update Record #{record.id}:" else logger.debug "create Record:" record = Record.new end logger.debug record_attribs.to_json record.update_attributes!( record_attribs ) end # lines.each end |