Class: RestaurantSection
- Inherits:
-
Object
- Object
- RestaurantSection
- Defined in:
- app/my_lib/restaurant_section.rb
Overview
Restaurant Section filter
Instance Method Summary collapse
- #as_json(context, minor_version_param) ⇒ Object
- #branch_section? ⇒ Boolean
- #by_city(city_id) ⇒ Object
- #cache_key ⇒ Object
- #collections ⇒ Object
- #compact_section? ⇒ Boolean
- #get_clevertap_event_name ⇒ Object
- #get_description ⇒ Object
- #get_footer ⇒ Object
- #get_icon ⇒ Object
- #get_punch_line ⇒ Object
- #get_slug ⇒ Object
- #get_tag_line ⇒ Object
- #get_title ⇒ Object
- #home_restaurant_section ⇒ Object
-
#initialize ⇒ RestaurantSection
constructor
A new instance of RestaurantSection.
- #nearest_promotion? ⇒ Boolean
- #page_number(number) ⇒ Object
- #per_page(number) ⇒ Object
- #restaurant_tag_section? ⇒ Boolean
- #section_number(section_no) ⇒ Object
- #set_context(context) ⇒ Object
- #set_location(location) ⇒ Object
- #sort_by ⇒ Object
- #thai_today ⇒ Object
Constructor Details
#initialize ⇒ RestaurantSection
Returns a new instance of RestaurantSection.
5 6 7 |
# File 'app/my_lib/restaurant_section.rb', line 5 def initialize @config = {} end |
Instance Method Details
#as_json(context, minor_version_param) ⇒ Object
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/my_lib/restaurant_section.rb', line 56 def as_json(context, minor_version_param) if restaurant_tag_section? filter = build_restaurant_tag filter.as_json(context, minor_version_param, {}). merge( success: true, message: nil, title: get_title, description: get_description, footer: , tag_line: get_tag_line, slug: get_slug, icon: get_icon, clevertap_event_name: get_clevertap_event_name, ).merge(home_section_attributes) elsif branch_section? = { serialization_context: context, serializer: ActiveModel::Serializer::CollectionSerializer, adapter: :json_api, each_serializer: Api::V5::BranchSerializer, } json = ActiveModelSerializers::SerializableResource.new(build_branch, ).as_json ads = fetch_ads('branch') json[:ads] = ads if ads.present? json.merge(success: true, message: nil, title: get_title, description: get_description, footer: , tag_line: get_tag_line, slug: get_slug, icon: get_icon, clevertap_event_name: get_clevertap_event_name).merge(home_section_attributes) elsif nearest_promotion? = {} [:each_serializer] = Api::V5::RestaurantSerializer .merge! serialization_context: context, serializer: ActiveModel::Serializer::CollectionSerializer, adapter: :json_api, minor_version: minor_version_param json = ActiveModelSerializers::SerializableResource.new(collections, ).as_json json.merge(success: true, message: nil, title: get_title, description: get_description, footer: , tag_line: get_tag_line, slug: get_slug, icon: get_icon, clevertap_event_name: get_clevertap_event_name).merge(home_section_attributes) else ads = fetch_ads('restaurant') filter = build_compact_restaurant json = filter.as_json(context, minor_version_param, { include: 'group_landing_page' }). merge(success: true, message: nil, title: get_title, description: get_description, footer: , tag_line: get_tag_line, slug: get_slug, icon: get_icon, next_reset_trending_at: next_reset_trending_at, clevertap_event_name: get_clevertap_event_name).merge(home_section_attributes) json[:ads] = ads if ads.present? json end end |
#branch_section? ⇒ Boolean
224 225 226 |
# File 'app/my_lib/restaurant_section.rb', line 224 def branch_section? config[:section_number] == 'section_5' end |
#by_city(city_id) ⇒ Object
29 30 31 32 |
# File 'app/my_lib/restaurant_section.rb', line 29 def by_city(city_id) config[:city_id] = city_id if city_id.to_i.positive? self end |
#cache_key ⇒ Object
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'app/my_lib/restaurant_section.rb', line 131 def cache_key return '' if config[:section_number].blank? ads_key = (Advertisement.send(config[:section_number].to_sym).cache_key if section_ads?) ck = if branch_section? CityHash.hash32([self.class.to_s, config[:section_number], start_date, end_date, config, Branch.maximum(:updated_at), Report.cached_all_cache_key, home_restaurant_section&.cache_key, I18n.locale, thai_today]) elsif restaurant_tag_section? CityHash.hash32([self.class.to_s, config[:section_number], config, RestaurantTag.maximum(:updated_at), Report.cached_all_cache_key, home_restaurant_section&.cache_key, I18n.locale, config[:city_id], thai_today]) elsif nearest_promotion? CityHash.hash32([self.class.to_s, config[:section_number], config, Restaurant.maximum(:updated_at), I18n.locale, config[:longitude], config[:latitude], thai_today, Report.cached_all_cache_key, home_restaurant_section&.cache_key, AdminSetting.enable_free_delivery_just_for_you]) else CityHash.hash32([self.class.to_s, config[:section_number], config, CompactRestaurant.maximum(:updated_at), I18n.locale, config[:city_id], Report.cached_all_cache_key, home_restaurant_section&.cache_key, next_reset_trending_at, thai_today]) end "#{cache_name_space}:#{ck}:#{ads_key}" end |
#collections ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/my_lib/restaurant_section.rb', line 42 def collections return [] if config[:section_number].blank? if nearest_promotion? build_nearest_promotion_restaurants elsif restaurant_tag_section? build_restaurant_tag elsif branch_section? build_branch else build_compact_restaurant.collections end end |
#compact_section? ⇒ Boolean
232 233 234 |
# File 'app/my_lib/restaurant_section.rb', line 232 def compact_section? !branch_section? && !restaurant_tag_section? end |
#get_clevertap_event_name ⇒ Object
212 213 214 |
# File 'app/my_lib/restaurant_section.rb', line 212 def get_clevertap_event_name I18n.t("home_screen.#{config[:section_number]}") || '' end |
#get_description ⇒ Object
188 189 190 |
# File 'app/my_lib/restaurant_section.rb', line 188 def get_description home_restaurant_section&.description(for_api: true) end |
#get_footer ⇒ Object
196 197 198 |
# File 'app/my_lib/restaurant_section.rb', line 196 def home_restaurant_section&.(for_api: true) end |
#get_icon ⇒ Object
204 205 206 |
# File 'app/my_lib/restaurant_section.rb', line 204 def get_icon home_restaurant_section&.icon end |
#get_punch_line ⇒ Object
184 185 186 |
# File 'app/my_lib/restaurant_section.rb', line 184 def get_punch_line home_restaurant_section&.punch_line(for_api: true) end |
#get_slug ⇒ Object
200 201 202 |
# File 'app/my_lib/restaurant_section.rb', line 200 def get_slug home_restaurant_section&.friendly_id || '' end |
#get_tag_line ⇒ Object
192 193 194 |
# File 'app/my_lib/restaurant_section.rb', line 192 def get_tag_line home_restaurant_section&.tag_line(for_api: true) end |
#get_title ⇒ Object
176 177 178 179 180 181 182 |
# File 'app/my_lib/restaurant_section.rb', line 176 def get_title if home_restaurant_section.blank? return I18n.t("home_screen.#{config[:section_number]}").presence || '' end home_restaurant_section.title(for_api: true) end |
#home_restaurant_section ⇒ Object
208 209 210 |
# File 'app/my_lib/restaurant_section.rb', line 208 def home_restaurant_section HomeSection.find_by(section_type: config[:section_number]) end |
#nearest_promotion? ⇒ Boolean
228 229 230 |
# File 'app/my_lib/restaurant_section.rb', line 228 def nearest_promotion? config[:section_number] == 'section_14' end |
#page_number(number) ⇒ Object
14 15 16 17 |
# File 'app/my_lib/restaurant_section.rb', line 14 def page_number(number) config[:page_number] = number.to_i if number.to_i.positive? self end |
#per_page(number) ⇒ Object
19 20 21 22 |
# File 'app/my_lib/restaurant_section.rb', line 19 def per_page(number) config[:per_page] = number.to_i if number.to_i.positive? self end |
#restaurant_tag_section? ⇒ Boolean
220 221 222 |
# File 'app/my_lib/restaurant_section.rb', line 220 def restaurant_tag_section? ['section_7', 'section_4', 'section_10'].include?(config[:section_number]) end |
#section_number(section_no) ⇒ Object
24 25 26 27 |
# File 'app/my_lib/restaurant_section.rb', line 24 def section_number(section_no) config[:section_number] = section_no if section_no.present? self end |
#set_context(context) ⇒ Object
9 10 11 12 |
# File 'app/my_lib/restaurant_section.rb', line 9 def set_context(context) config[:serialization_context] = context if context.present? self end |
#set_location(location) ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/my_lib/restaurant_section.rb', line 34 def set_location(location) return if location.blank? config[:longitude] = location[:lon] config[:latitude] = location[:lat] self end |
#sort_by ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'app/my_lib/restaurant_section.rb', line 236 def sort_by case config[:section_number].to_s when 'section_1' 'new' when 'section_3' 'trending' # 'seven_seven_hashtag' when 'section_6' 'under_1000b' when 'section_8' 'staycation' when 'section_9' 'premium_delivery_offers_hashtag' when 'section_11' # 'top_dine_in' 'w1_recommendation' when 'section_12' 'section_12' when 'section_13' 'rank' else '' end end |
#thai_today ⇒ Object
216 217 218 |
# File 'app/my_lib/restaurant_section.rb', line 216 def thai_today Time.thai_time.to_date end |