Class: EventDrivenServices::HhSearch::Schemas::RestaurantTagGroupSchema

Inherits:
Object
  • Object
show all
Defined in:
app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb

Constant Summary collapse

VALID_EVENT_TYPES =
[
  EventDrivenClient::Constants::UPDATE_EVENT,
  EventDrivenClient::Constants::DELETE_EVENT,
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(restaurant_tag_group_param, event_type) ⇒ RestaurantTagGroupSchema

Returns a new instance of RestaurantTagGroupSchema.



12
13
14
15
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb', line 12

def initialize(restaurant_tag_group_param, event_type)
  @restaurant_tag_group = validate_restaurant_tag_group(restaurant_tag_group_param)
  @event_type = validate_event_type(event_type)
end

Instance Attribute Details

#event_typeObject (readonly)

Returns the value of attribute event_type.



5
6
7
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb', line 5

def event_type
  @event_type
end

#restaurant_tag_groupObject (readonly)

Returns the value of attribute restaurant_tag_group.



5
6
7
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb', line 5

def restaurant_tag_group
  @restaurant_tag_group
end

Instance Method Details

#serializeHash

Serialize the restaurant tag group to a hash

Returns:

  • (Hash)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb', line 20

def serialize
  if event_type == EventDrivenClient::Constants::DELETE_EVENT
    default_payload
  else
    payload = default_payload.dup

    # Add title for all available locales dynamically
    MyLocaleManager.available_locales.each do |locale|
      name_attr = "name_#{locale}"
      if restaurant_tag_group.respond_to?(name_attr)
        # Use fallback to default locale for empty values
        payload["title_#{locale}".to_sym] = restaurant_tag_group.public_send(name_attr).presence ||
          restaurant_tag_group.public_send("name_#{MyLocaleManager.default_locale}")
      end
    end

    payload
  end
end

#serialize_as_jsonString

Serialize the restaurant tag group to a JSON string

Returns:

  • (String)


43
44
45
# File 'app/services/event_driven_services/hh_search/schemas/restaurant_tag_group_schema.rb', line 43

def serialize_as_json
  serialize.to_json
end