5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 14:26:22 +00:00
panel/app/models/maintenance.rb

55 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2020-06-16 16:35:08 +00:00
# frozen_string_literal: true
# En mantenimiento
class Maintenance < ApplicationRecord
extend Mobility
translates :message, type: :string, locale_accessors: true
2020-09-11 17:26:19 +00:00
# Renderiza el mensaje una sola vez
#
# @return [String]
def to_html
@renderized_message ||= {}
@renderized_message[message.hash.to_s] ||= CommonMarker.render_doc(message, %i[FOOTNOTES SMART], %i[table strikethrough autolink]).to_html.html_safe
end
# Como no sabemos en qué zona horaria están les usuaries, generamos la
# URL para convertir el tiempo estimado a la zona local, visitando
# otro servicio.
#
# @return [String]
def estimated_from_time_is
@estimated_from_time_is ||= {}
@estimated_from_time_is[cache_key_for_attr(estimated_from)] ||= time_is(estimated_from)
end
# @see estimated_from_time_is
# @return [String]
def estimated_to_time_is
@estimated_to_time_is ||= {}
@estimated_to_time_is[cache_key_for_attr(estimated_to)] ||= time_is(estimated_to)
end
# @see estimated_from_time_is
# @return [String]
def updated_at_time_is
@updated_at_time_is ||= {}
@updated_at_time_is[cache_key_for_attr(updated_at)] ||= time_is(updated_at)
end
private
def cache_key_for_attr(attr)
attr.hash.to_s + I18n.locale.to_s
end
# Devuelve la URL
#
# @param [Time]
# @return [String]
def time_is(time)
"https://time.is/#{I18n.locale}/compare/#{time.utc.strftime('%H%M_%d_%B_%Y_in_%Z')}"
end
2020-06-16 16:35:08 +00:00
end