Class: Booth::Cooldowns::DistanceOfTime

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

Instance Method Summary collapse

Methods included from MethodObject

included

Instance Method Details

#callObject



9
10
11
12
13
14
15
# File 'lib/booth/cooldowns/distance_of_time.rb', line 9

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



33
34
35
# File 'lib/booth/cooldowns/distance_of_time.rb', line 33

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

#distance_in_minutesObject



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

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

#distance_in_secondsObject



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

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

#show_hours?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/booth/cooldowns/distance_of_time.rb', line 17

def show_hours?
  distance_in_hours.positive?
end

#show_minutes?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/booth/cooldowns/distance_of_time.rb', line 21

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

  distance_in_minutes.nonzero?
end

#show_seconds?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/booth/cooldowns/distance_of_time.rb', line 27

def show_seconds?
  return true if distance_in_seconds < 60

  distance_in_hours.zero? && distance_in_minutes.zero?
end