Class: Booth::Core::Cooldowns::DistanceOfTime

Inherits:
Object
  • Object
show all
Includes:
Calls
Defined in:
lib/booth/core/cooldowns/distance_of_time.rb

Instance Method Summary collapse

Instance Method Details

#callObject



12
13
14
15
16
17
18
# File 'lib/booth/core/cooldowns/distance_of_time.rb', line 12

def call
  result = []
  result.push("#{distance_in_hours} h") if show_hours?
  result.push("#{distance_in_minutes} min") if show_minutes?
  result.push("#{distance_in_seconds} s") if show_seconds?
  result.join(' ')
end

#distance_in_hoursObject



36
37
38
# File 'lib/booth/core/cooldowns/distance_of_time.rb', line 36

def distance_in_hours
  ((till - from).abs / 3600).floor
end

#distance_in_minutesObject



40
41
42
# File 'lib/booth/core/cooldowns/distance_of_time.rb', line 40

def distance_in_minutes
  (((till - from).abs % 3600) / 60).round
end

#distance_in_secondsObject



44
45
46
# File 'lib/booth/core/cooldowns/distance_of_time.rb', line 44

def distance_in_seconds
  (till - from).abs.round
end

#show_hours?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/booth/core/cooldowns/distance_of_time.rb', line 20

def show_hours?
  distance_in_hours.positive?
end

#show_minutes?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/booth/core/cooldowns/distance_of_time.rb', line 24

def show_minutes?
  return false if (((till - from).abs % 3600) / 60) < 1

  distance_in_minutes.nonzero?
end

#show_seconds?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/booth/core/cooldowns/distance_of_time.rb', line 30

def show_seconds?
  return true if distance_in_seconds < 60

  distance_in_hours.zero? && distance_in_minutes.zero?
end