Class: SportDb::Import::ClubHistoryIndex
- Inherits:
-
Object
- Object
- SportDb::Import::ClubHistoryIndex
- Defined in:
- lib/sportdb/formats/team/club_index_history.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
Instance Method Summary collapse
-
#add(rec_or_recs) ⇒ Object
add club record / alt_names.
- #add_history(club_rec, keyword, season, args) ⇒ Object
- #catalog ⇒ Object
- #errors? ⇒ Boolean
-
#find_name_by(name:, season:) ⇒ Object
todo/check: move as method to club struct later - to always use club reference returns (simply) name as string for now or nil - why? why not?.
-
#initialize ⇒ ClubHistoryIndex
constructor
A new instance of ClubHistoryIndex.
-
#mappings ⇒ Object
todo/check: rename to records or histories or something - why? why not?.
-
#strip_geo(name) ⇒ Object
helpers.
Constructor Details
#initialize ⇒ ClubHistoryIndex
Returns a new instance of ClubHistoryIndex.
34 35 36 37 |
# File 'lib/sportdb/formats/team/club_index_history.rb', line 34 def initialize @clubs = {} ## clubs (indexed) by canonical name @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
39 40 41 |
# File 'lib/sportdb/formats/team/club_index_history.rb', line 39 def errors @errors end |
Class Method Details
.build(path) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sportdb/formats/team/club_index_history.rb', line 9 def self.build( path ) pack = Package.new( path ) ## lets us use direcotry or zip archive recs = [] pack.each_clubs_history do |entry| recs += ClubHistoryReader.parse( entry.read ) end recs index = new index.add( recs ) index end |
Instance Method Details
#add(rec_or_recs) ⇒ Object
add club record / alt_names
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/formats/team/club_index_history.rb', line 57 def add( rec_or_recs ) ## add club record / alt_names recs = rec_or_recs.is_a?( Array ) ? rec_or_recs : [rec_or_recs] ## wrap (single) rec in array recs.each do |rec| keyword = rec[0] season_key = rec[1] args = rec[2..-1] ## get rest of args e.g. one, two or more ## note: for now only add (re)name history season records, ## that is, skip MERGE and BANKRUPT for now ## and incl. only RENAME, REFORM, MOVE for now next if ['MERGE', 'BANKRUPT'].include?( keyword ) name_old = strip_geo( args[0][0] ) ## note: strip optional geo part from name name_new = strip_geo( args[1][0] ) country_old = args[0][1] country_new = args[1][1] club_old = catalog.clubs.find_by!( name: name_old, country: country_old ) club_new = catalog.clubs.find_by!( name: name_new, country: country_new ) ## note use season obj for now (and NOT key) - why? why not? season = Season.parse( season_key ) ## todo/check: ## check if club_old and club_new reference different club record!! ## examples - RB II -> Liefering ?? or ## FC Pasching -> OOE Juniors ?? ## Austria Salzburg -> RB Salburg ?? ## for now always add name history to both - why? why not? add_history( club_old, keyword, season, args ) ## note: allow for now different club references ## but maybe warn later - why? why not? ## add history to both for now add_history( club_new, keyword, season, args ) if club_old != club_new end # each rec end |
#add_history(club_rec, keyword, season, args) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sportdb/formats/team/club_index_history.rb', line 45 def add_history( club_rec, keyword, season, args ) ## note use season obj for now (and NOT key) - why? why not? rec = @clubs[ club_rec.name ] ||= [] rec << [season, [keyword, args]] ## note: always keep records sorted by season_key for now ## check if 2010 and 2010/11 is in order using alpha sort?? (see argentina) rec.sort! { |l,r| r[0] <=> l[0] } end |
#catalog ⇒ Object
25 |
# File 'lib/sportdb/formats/team/club_index_history.rb', line 25 def catalog() Import.catalog; end |
#errors? ⇒ Boolean
40 |
# File 'lib/sportdb/formats/team/club_index_history.rb', line 40 def errors?() @errors.empty? == false; end |
#find_name_by(name:, season:) ⇒ Object
todo/check: move as method to club struct later - to always use club reference
returns (simply) name as string for now or nil - why? why not?
history entry example
Arsenal FC“=> [[1927/28, [”RENAME“, [[”The Arsenal FC, London“, ”eng“], [”Arsenal FC“, ”eng“]]]],
[1914/15, ["RENAME", [["Woolwich Arsenal FC, London", "eng"], ["The Arsenal FC", "eng"]]]],
[1892/93, ["RENAME", [["Royal Arsenal FC, London", "eng"], ["Woolwich Arsenal FC", "eng"]]]]],
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/sportdb/formats/team/club_index_history.rb', line 108 def find_name_by( name:, season: ) recs = @clubs[ name ] if recs season = Season( season ) ## make sure season is a season obj (and NOT a string) ## check season records for name; use linear search (assume only few records) recs.each do |rec| if season >= rec[0] return strip_geo( rec[1][1][1][0] ) # use second arg end end ## if we get here use last name strip_geo( recs[-1][1][1][0][0] ) # use first arg else nil end end |
#mappings ⇒ Object
todo/check: rename to records or histories or something - why? why not?
42 |
# File 'lib/sportdb/formats/team/club_index_history.rb', line 42 def mappings() @clubs; end |
#strip_geo(name) ⇒ Object
helpers
127 128 129 130 |
# File 'lib/sportdb/formats/team/club_index_history.rb', line 127 def strip_geo( name ) ## e.g. Arsenal, London => Arsenal name.split(',')[0].strip end |