2021-08-04 03:11:10 +00:00
|
|
|
class RulingBusInfo
|
2022-11-24 16:37:19 +00:00
|
|
|
include RulingBusConcern
|
2021-08-04 03:11:10 +00:00
|
|
|
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
|
2021-08-04 04:43:04 +00:00
|
|
|
field :locale, type: String
|
2021-08-04 03:11:10 +00:00
|
|
|
field :hint, type: String, default: "", localize: true
|
|
|
|
|
2021-08-04 04:43:04 +00:00
|
|
|
def locale
|
2021-08-04 04:50:57 +00:00
|
|
|
super() || I18n.locale.to_s.capitalize
|
2021-08-04 04:43:04 +00:00
|
|
|
end
|
2021-08-04 03:11:10 +00:00
|
|
|
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
|