Class: Booth::Core::Cooldowns::DistanceOfTime
- Inherits:
-
Object
- Object
- Booth::Core::Cooldowns::DistanceOfTime
- Includes:
- Calls
- Defined in:
- lib/booth/core/cooldowns/distance_of_time.rb
Instance Method Summary collapse
- #call ⇒ Object
- #distance_in_hours ⇒ Object
- #distance_in_minutes ⇒ Object
- #distance_in_seconds ⇒ Object
- #show_hours? ⇒ Boolean
- #show_minutes? ⇒ Boolean
- #show_seconds? ⇒ Boolean
Instance Method Details
#call ⇒ Object
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_hours ⇒ Object
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_minutes ⇒ Object
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_seconds ⇒ Object
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
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
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
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 |