Class: SportDb::Model::Track
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SportDb::Model::Track
- Defined in:
- lib/sportdb/models/track.rb
Class Method Summary collapse
- .create_or_update_from_values(new_attributes, values) ⇒ Object
-
.known_tracks_table ⇒ Object
fix: move known_tracks_table to event!!! (e.g. scoped by event).
Class Method Details
.create_or_update_from_values(new_attributes, values) ⇒ Object
21 22 23 24 25 26 27 28 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 |
# File 'lib/sportdb/models/track.rb', line 21 def self.create_or_update_from_values( new_attributes, values ) ## fix: add/configure logger for ActiveRecord!!! logger = LogKernel::Logger.root ## check optional values values.each_with_index do |value, index| if value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc. value_country = Country.find_by_key!( value ) new_attributes[ :country_id ] = value_country.id elsif value =~ /^[A-Z]{3}$/ ## assume three-letter code e.g. AUS, MAL, etc. new_attributes[ :code ] = value else ## todo: assume title2 ?? ## assume title2 if title2 is empty (not already in use) ## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z] # issue warning: unknown type for value logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}" end end rec = Track.find_by_key( new_attributes[ :key ] ) if rec.present? logger.debug "update Track #{rec.id}-#{rec.key}:" else logger.debug "create Track:" rec = Track.new end logger.debug new_attributes.to_json rec.update_attributes!( new_attributes ) end |
.known_tracks_table ⇒ Object
fix: move known_tracks_table to event!!! (e.g. scoped by event)
16 17 18 |
# File 'lib/sportdb/models/track.rb', line 16 def self.known_tracks_table @@known_tracks_table ||= TextUtils.build_title_table_for( Track.all ) end |