class RulingBusInfo include Mongoid::Document include Mongoid::Timestamps include OrbitCategory::Categorizable field :city, type: String, default: "" field :location_code, type: String, default: "" field :monitor_point, type: String, default: "" field :destination, type: String, default: "" field :route_names, type: Array, default: [] field :cache_data, type: Hash, default: {} field :direction, type: Integer, default: 0 field :locale, type: String field :hint, type: String, default: "", localize: true def locale super() || I18n.locale.to_s.capitalize end def monitor_point_show(locale=nil) locale = self.class.get_locale if locale.nil? (self.cache_data[:bus].blank? ? self.cache_data[:pbus][0][0][0][locale] : self.cache_data[:bus][0][0][0][locale] rescue "") end def destination_show(locale=nil) locale = self.class.get_locale if locale.nil? (self.cache_data[:bus].blank? ? self.cache_data[:pbus][0][0][1][locale] : self.cache_data[:bus][0][0][1][locale] rescue "") end def city_show() I18n.locale.to_s == 'zh_tw' ? RulingBusCity.first.dict[self.city] : self.city.gsub(/(?!^)[A-Z]/, ' \0') end def self.get_locale I18n.locale.to_s == 'zh_tw' ? 'Zh_tw' : 'En' end def regenerate_cache_data data = RulingBusesHelper.get_bus_with_direction_from_a_to_b(self.city,self.location_code,self.monitor_point,self.destination,self.locale,self.direction) self.update_attributes(cache_data: data) end end