Class: Hungrytable::RestaurantSearch

Inherits:
Object
  • Object
show all
Includes:
RequestExtensions
Defined in:
lib/hungrytable/restaurant_search.rb

Overview

Searches for available reservation times at a restaurant

Constant Summary collapse

ATTRIBUTES =

Attributes that map directly to API response fields

i[
  cuisine_type
  early_security_ID
  early_time
  error_ID
  error_message
  exact_security_ID
  exact_time
  later_security_ID
  later_time
  latitude
  longitude
  neighborhood_name
  restaurant_name
  results_key
  no_times_message
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(restaurant, opts = {}) ⇒ RestaurantSearch

Returns a new instance of RestaurantSearch.



29
30
31
32
33
34
35
36
# File 'lib/hungrytable/restaurant_search.rb', line 29

def initialize(restaurant, opts = {})
  @opts = opts
  ensure_required_opts
  validate_date_time_type
  validate_party_size
  @requester = opts[:requester] || GetRequest
  @restaurant = restaurant
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



27
28
29
# File 'lib/hungrytable/restaurant_search.rb', line 27

def opts
  @opts
end

#restaurantObject (readonly)

Returns the value of attribute restaurant.



27
28
29
# File 'lib/hungrytable/restaurant_search.rb', line 27

def restaurant
  @restaurant
end

Instance Method Details

#ideal_security_idString?

Get the best available security ID

Returns:

  • (String, nil)

    the ideal security ID for slotlock



55
56
57
# File 'lib/hungrytable/restaurant_search.rb', line 55

def ideal_security_id
  exact_security_ID || early_security_ID || later_security_ID
end

#ideal_timeString?

Get the best available time

Returns:

  • (String, nil)

    the ideal time for reservation



61
62
63
# File 'lib/hungrytable/restaurant_search.rb', line 61

def ideal_time
  exact_time || early_time || later_time
end

#party_sizeInteger

Get the party size for this search

Returns:

  • (Integer)

    number of people



67
68
69
# File 'lib/hungrytable/restaurant_search.rb', line 67

def party_size
  opts[:party_size]
end

#valid?Boolean

Check if the search was valid

Returns:

  • (Boolean)

    true if no errors



40
41
42
# File 'lib/hungrytable/restaurant_search.rb', line 40

def valid?
  error_ID.to_s == '0'
end