Class: ImHungry::FoodTruck

Inherits:
Object
  • Object
show all
Includes:
TzHelper
Defined in:
lib/im_hungry/food_truck.rb

Constant Summary collapse

TZ =
'US/Pacific'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TzHelper

#current_time, #parse_time, #tz_offset

Constructor Details

#initialize(food_truck) ⇒ FoodTruck

Returns a new instance of FoodTruck.



8
9
10
11
12
13
14
# File 'lib/im_hungry/food_truck.rb', line 8

def initialize(food_truck)
  self.start24 = food_truck["start24"]
  self.end24 = food_truck["end24"]
  self.dayorder = food_truck["dayorder"]
  self.applicant = food_truck["applicant"]
  self.location = food_truck["location"]
end

Instance Attribute Details

#applicantObject

Returns the value of attribute applicant.



6
7
8
# File 'lib/im_hungry/food_truck.rb', line 6

def applicant
  @applicant
end

#dayorderObject

Returns the value of attribute dayorder.



6
7
8
# File 'lib/im_hungry/food_truck.rb', line 6

def dayorder
  @dayorder
end

#end24Object

Returns the value of attribute end24.



6
7
8
# File 'lib/im_hungry/food_truck.rb', line 6

def end24
  @end24
end

#locationObject

Returns the value of attribute location.



6
7
8
# File 'lib/im_hungry/food_truck.rb', line 6

def location
  @location
end

#start24Object

Returns the value of attribute start24.



6
7
8
# File 'lib/im_hungry/food_truck.rb', line 6

def start24
  @start24
end

Instance Method Details

#currently_open?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/im_hungry/food_truck.rb', line 40

def currently_open?
  is_current_day_of_week? && has_started? && has_ended?
end

#end_timeObject



24
25
26
# File 'lib/im_hungry/food_truck.rb', line 24

def end_time
  parse_time(end24)
end

#has_ended?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/im_hungry/food_truck.rb', line 36

def has_ended?
  end_time > current_time
end

#has_started?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/im_hungry/food_truck.rb', line 32

def has_started?
  start_time <= current_time
end

#is_current_day_of_week?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/im_hungry/food_truck.rb', line 28

def is_current_day_of_week?
  wday == current_time.wday
end

#start_timeObject



20
21
22
# File 'lib/im_hungry/food_truck.rb', line 20

def start_time
  parse_time(start24)
end

#time_zoneObject



44
45
46
# File 'lib/im_hungry/food_truck.rb', line 44

def time_zone
  TZ
end

#to_sObject



48
49
50
# File 'lib/im_hungry/food_truck.rb', line 48

def to_s
  "#{applicant} at #{location}"
end

#wdayObject



16
17
18
# File 'lib/im_hungry/food_truck.rb', line 16

def wday
  dayorder&.to_i
end