Class: Booth::Cooldowns::DistanceOfTime
- Inherits:
-
Object
- Object
- Booth::Cooldowns::DistanceOfTime
- Includes:
- MethodObject
- Defined in:
- lib/booth/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
Methods included from MethodObject
Instance Method Details
#call ⇒ Object
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_hours ⇒ Object
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_minutes ⇒ Object
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_seconds ⇒ Object
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
17 18 19 |
# File 'lib/booth/cooldowns/distance_of_time.rb', line 17 def show_hours? distance_in_hours.positive? end |
#show_minutes? ⇒ 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
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 |