Class: SportDb::NationalTeamReader
- Inherits:
-
Object
- Object
- SportDb::NationalTeamReader
- Includes:
- LogUtils::Logging, FixtureHelpers, Model, TextUtils::ValueHelper
- Defined in:
- lib/sportdb/readers/national_team.rb
Overview
squad/roster reader for national teams
Constant Summary
Constants included from Model
Model::City, Model::Continent, Model::Country, Model::Person, 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 = {}) ⇒ NationalTeamReader
constructor
A new instance of NationalTeamReader.
- #read(name, more_attribs = {}) ⇒ Object
- #read_worker(reader) ⇒ Object
- #titleize(str) ⇒ Object
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 = {}) ⇒ NationalTeamReader
Returns a new instance of NationalTeamReader.
24 25 26 |
# File 'lib/sportdb/readers/national_team.rb', line 24 def initialize( include_path, opts = {} ) @include_path = include_path end |
Instance Attribute Details
#include_path ⇒ Object (readonly)
Returns the value of attribute include_path.
21 22 23 |
# File 'lib/sportdb/readers/national_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 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 |
# File 'lib/sportdb/readers/national_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})..." # event @event = Event.find( more_attribs[:event_id] ) pp @event ## check/fix: ## allow three letter codes ## assume three letter code are *team* codes (e.g. fdr, gdr, etc) ## not country code (allows multiple teams per country) ### check for country_id ## fix: check for country_key - allow (convert to country_id) country = Country.find( more_attribs[:country_id] ) logger.info " find national team squad/lineup for #{country.name}" ## todo/fix: find national team for country - use event.teams w/ where country.id ?? ### for now assume country code matches team for now (do NOT forget to downcase e.g. BRA==bra) logger.info " assume country code == team code for #{country.code}" ## note: use @team - share/use in worker method @team = Team.find_by_key!( country.code.downcase ) pp @team ### SportDb.lang.lang = LangChecker.new.analyze( name, include_path ) reader = LineReader.new( path ) logger.info " persons count for country: #{country.persons.count}" known_persons_old = TextUtils.build_title_table_for( country.persons ) ### fix: add auto camelcase/titlecase ## move to textutils ## make it an option for name to auto Camelcase/titlecase? ## e.g. BONFIM COSTA SANTOS becomes ## Bonfim Costa Santos etc. ## fix: better move into person parser? ## store all alt_names titleized!!!!! @known_persons = [] known_persons_old.each do |person_pair| key = person_pair[0] values = person_pair[1].map { |value| titleize(value) } @known_persons << [ key, values ] end pp @known_persons read_worker( reader ) Prop.create_from_fixture!( name, path ) end |
#read_worker(reader) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/sportdb/readers/national_team.rb', line 107 def read_worker( reader ) pos_counter = 999000 # pos counter for undefined players w/o pos reader.each_line do |line| logger.debug " line: >#{line}<" cut_off_end_of_line_comment!( line ) pos = find_leading_pos!( line ) if pos.nil? pos_counter+=1 ## e.g. 999001,999002 etc. pos = pos_counter end # 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 ) if person.nil? logger.error " !!!!!! no mapping found for player in line >#{line}<" end 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, person_id: person.id, team_id: @team.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 |
#titleize(str) ⇒ Object
100 101 102 103 104 |
# File 'lib/sportdb/readers/national_team.rb', line 100 def titleize( str ) ## fix: for now works only with ASCII only ## words 2 letters and ups str.gsub(/\b[A-Z]{2,}\b/) { |match| match.capitalize } end |