Class: EventDrivenServices::HhSearch::Schemas::RestaurantTagSchema
- Inherits:
-
Object
- Object
- EventDrivenServices::HhSearch::Schemas::RestaurantTagSchema
- Includes:
- Helpers::RestaurantTagHelper
- Defined in:
- app/services/event_driven_services/hh_search/schemas/restaurant_tag_schema.rb
Constant Summary collapse
- VALID_EVENT_TYPES =
[ EventDrivenClient::Constants::INDEX_EVENT, EventDrivenClient::Constants::CREATE_EVENT, EventDrivenClient::Constants::UPDATE_EVENT, EventDrivenClient::Constants::DELETE_EVENT, ].freeze
Instance Attribute Summary collapse
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#restaurant_tag ⇒ Object
readonly
Returns the value of attribute restaurant_tag.
Instance Method Summary collapse
-
#initialize(restaurant_tag_param, event_type) ⇒ RestaurantTagSchema
constructor
A new instance of RestaurantTagSchema.
-
#serialize ⇒ Hash
Serialize the restaurant tag to a hash.
-
#serialize_as_json ⇒ String
Serialize the restaurant tag to a JSON string.
Constructor Details
#initialize(restaurant_tag_param, event_type) ⇒ RestaurantTagSchema
Returns a new instance of RestaurantTagSchema.
16 17 18 19 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_schema.rb', line 16 def initialize(restaurant_tag_param, event_type) @restaurant_tag = validate_restaurant_tag(restaurant_tag_param) @event_type = validate_event_type(event_type) end |
Instance Attribute Details
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
7 8 9 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_schema.rb', line 7 def event_type @event_type end |
#restaurant_tag ⇒ Object (readonly)
Returns the value of attribute restaurant_tag.
7 8 9 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_schema.rb', line 7 def restaurant_tag @restaurant_tag end |
Instance Method Details
#serialize ⇒ Hash
Serialize the restaurant tag to a hash
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_schema.rb', line 24 def serialize if event_type == EventDrivenClient::Constants::DELETE_EVENT default_payload else payload = default_payload.merge( city_id: restaurant_tag.city_id, category: restaurant_tag.category, synonyms: synonyms, total_restaurants: total_restaurants_for_all_cities(restaurant_tag), ) # Add title for all available locales dynamically MyLocaleManager.available_locales.each do |locale| payload["title_#{locale}".to_sym] = restaurant_tag.title_format(locale, for_api: true) end payload end end |
#serialize_as_json ⇒ String
Serialize the restaurant tag to a JSON string
47 48 49 |
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_schema.rb', line 47 def serialize_as_json serialize.to_json end |