module ApplicationHelper
def truncate_html(html, length, &block)
truncate html.nil? ? '' : sanitize(html, tags: {}).squish , length: length, separator: ' ', &block
end
def is_administrator?
current_account.present? && current_account.administrator.present?
end
def show_amount(amount)
"#{((amount || 0) * Bank::SATOSHI_COEFF).round} SATOSHI".html_safe
end
def to_d digits_after_dot, value
if value.present?
"%.#{digits_after_dot}f" % value
else
value
end
end
def localize_datetime(date)
"#{l date.to_date} #{date.strftime('%H:%M:%S')}" if date.present?
end
def timer_timeslot(seconds)
[60, 60, 1000].map { |count| seconds, n = seconds.divmod(count); n.to_s.rjust(2, '0') }.reverse.join(':')
end
def humanize_timeslot(seconds)
[[60, 'second'], [60, 'minute'], [24, 'hour'], [1000, 'day']].map { |count, name|
if seconds > 0
seconds, n = seconds.divmod(count)
n > 0 ? pluralize(n.to_i, name) : nil
end
}.compact.reverse.join(', ')
end
end