Class: Advertisement

Inherits:
ApplicationRecord show all
Extended by:
Enumerize
Defined in:
app/models/advertisement.rb

Constant Summary collapse

ADS_LOCATION_AND_TYPE =
{
  section_1: 'CompactRestaurant',
  section_3: 'CompactRestaurant',
  section_5: 'Branch',
  section_11: 'CompactRestaurant',
  section_12: 'CompactRestaurant',
  search_suggest: 'Restaurant',
  search_page: 'Restaurant',
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Instance Attribute Details

#branch_idObject

Returns the value of attribute branch_id.



27
28
29
# File 'app/models/advertisement.rb', line 27

def branch_id
  @branch_id
end

Returns the value of attribute featured_restaurant_id.



27
28
29
# File 'app/models/advertisement.rb', line 27

def featured_restaurant_id
  @featured_restaurant_id
end

#restaurant_idObject

Returns the value of attribute restaurant_id.



27
28
29
# File 'app/models/advertisement.rb', line 27

def restaurant_id
  @restaurant_id
end

#restaurant_tag_idObject

Returns the value of attribute restaurant_tag_id.



27
28
29
# File 'app/models/advertisement.rb', line 27

def restaurant_tag_id
  @restaurant_tag_id
end

Class Method Details

.ads_locationsObject



109
110
111
112
113
114
115
116
117
118
119
# File 'app/models/advertisement.rb', line 109

def self.ads_locations
  Advertisement::ADS_LOCATION_AND_TYPE.keys.index_by do |location|
    home_section = HomeSection.find_by(section_type: location)
    if home_section
      home_section.title
    else
      # see config/locales/home.en.yml for the translation mapping
      I18n.t("home_screen.#{location}")
    end
  end
end

Instance Method Details

#clear_content_cacheObject



121
122
123
124
125
# File 'app/models/advertisement.rb', line 121

def clear_content_cache
  advertisable.touch
  advertisable.refresh_view_cache_key if advertisable.respond_to?(:view_cache_key)
  true
end

#expired?Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
# File 'app/models/advertisement.rb', line 84

def expired?
  time_zone = if advertisable.respond_to? :time_zone
                advertisable.time_zone
              else
                Time::THAILAND_ZONE
              end
  today = Time.use_zone(time_zone) { Time.zone.today }
  end_date < today
end

#init_advertisable_idObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/models/advertisement.rb', line 94

def init_advertisable_id
  return if advertisable_id.blank?

  case advertisable_type
  when 'Restaurant'
    self.restaurant_id = advertisable_id
  when 'CompactRestaurant'
    self.featured_restaurant_id = advertisable_id
  when 'Branch'
    self.branch_id = advertisable_id
  when 'RestaurantTag'
    self.restaurant_tag_id = advertisable_id
  end
end