Class: Tosuto::DiningOption

Inherits:
Resource show all
Defined in:
lib/tosuto/dining_option.rb

Constant Summary collapse

ENDPOINT =
'/config/v2/diningOptions'.freeze
CARRYOUT_MATCH =
%w[carryout].freeze
DSP_MATCH =
%w[delivery door grub postmates uber].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

attr_collections, attr_objects, encode_form_data, #inspect, #parse_collection, #parse_object, #set_attribute, #set_attributes, #underscore

Constructor Details

#initialize(hash) ⇒ DiningOption

Returns a new instance of DiningOption.



16
17
18
# File 'lib/tosuto/dining_option.rb', line 16

def initialize(hash)
  set_attributes(hash)
end

Instance Attribute Details

#entity_typeObject

Returns the value of attribute entity_type.



8
9
10
# File 'lib/tosuto/dining_option.rb', line 8

def entity_type
  @entity_type
end

#external_idObject

Returns the value of attribute external_id.



8
9
10
# File 'lib/tosuto/dining_option.rb', line 8

def external_id
  @external_id
end

#guidObject

Returns the value of attribute guid.



8
9
10
# File 'lib/tosuto/dining_option.rb', line 8

def guid
  @guid
end

Instance Method Details

#carryout?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/tosuto/dining_option.rb', line 38

def carryout?
  CARRYOUT_MATCH.any? { |carryout| name&.downcase&.match?(carryout) }
end

#delivery?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/tosuto/dining_option.rb', line 46

def delivery?
  behavior == 'DELIVERY' || (dsp? && !carryout?)
end

#dsp?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/tosuto/dining_option.rb', line 34

def dsp?
  DSP_MATCH.any? { |dsp| name&.downcase&.match?(dsp) }
end

#get_details(token:, restaurant_id:, api: API.new) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tosuto/dining_option.rb', line 20

def get_details(token:, restaurant_id:, api: API.new)
  url = "#{ENDPOINT}/#{guid}"
  response = api.request(
    :get,
    url,
    restaurant_id: restaurant_id,
    token: token,
  )
  raise response.error unless response.success?

  set_attributes(response.json_body)
  self
end

#take_out?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/tosuto/dining_option.rb', line 42

def take_out?
  behavior == 'TAKE_OUT' && (carryout? || !dsp?)
end