Class: Turbovax::Handlers::LocationHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/turbovax/handlers/location_handler.rb

Overview

Given a list of locations, tweet appointment info for each location

Instance Method Summary collapse

Constructor Details

#initialize(locations) ⇒ LocationHandler

Returns a new instance of LocationHandler.



9
10
11
# File 'lib/turbovax/handlers/location_handler.rb', line 9

def initialize(locations)
  @locations = locations
end

Instance Method Details

#appointment_time_formatObject

Format of each individual appointment time. See APIdoc for format apidock.com/ruby/DateTime/strftime

Examples:

Datetime to default time format

Wed, 21 Apr 2021 09:23:15 -0400 => 9:23AM


49
50
51
# File 'lib/turbovax/handlers/location_handler.rb', line 49

def appointment_time_format
  "%-l:%M%p"
end

#daily_appointment_limitObject

Max number of appointment times included per day



33
34
35
# File 'lib/turbovax/handlers/location_handler.rb', line 33

def daily_appointment_limit
  3
end

#date_formatObject

Format of each individual date. See APIdoc for format apidock.com/ruby/DateTime/strftime

Examples:

Datetime to default time format

Wed, 21 Apr 2021 09:23:15 -0400 => Apr 21


41
42
43
# File 'lib/turbovax/handlers/location_handler.rb', line 41

def date_format
  "%b %-e"
end

#day_limitObject

Max number of days included in a tweet



28
29
30
# File 'lib/turbovax/handlers/location_handler.rb', line 28

def day_limit
  3
end

#execute!Object



13
14
15
16
17
18
19
20
# File 'lib/turbovax/handlers/location_handler.rb', line 13

def execute!
  count = 0
  @locations.each do |location|
    next if count >= max_location_limit

    count += 1 if handle_location(location)
  end
end

#max_location_limitObject

Max locations to tweet at a given time



23
24
25
# File 'lib/turbovax/handlers/location_handler.rb', line 23

def max_location_limit
  2
end

#should_tweet_for_location(location) ⇒ Boolean

Override this method to to add caching logic

Returns:

  • (Boolean)


55
56
57
# File 'lib/turbovax/handlers/location_handler.rb', line 55

def should_tweet_for_location(location)
  location.available
end