Module: GoodJob::ApplicationHelper

Includes:
IconsHelper
Defined in:
app/helpers/good_job/application_helper.rb

Constant Summary

Constants included from IconsHelper

IconsHelper::STATUS_COLOR, IconsHelper::STATUS_ICONS

Instance Method Summary collapse

Methods included from IconsHelper

#icons_path, #render_icon, #status_badge, #status_icon

Instance Method Details

#format_duration(sec) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/good_job/application_helper.rb', line 10

def format_duration(sec)
  return unless sec
  return "" if sec.is_a?(String) # pg interval support added in Rails 6.1

  if sec < 1
    t 'good_job.duration.milliseconds', ms: (sec * 1000).floor
  elsif sec < 10
    t 'good_job.duration.less_than_10_seconds', sec: number_with_delimiter(sec.floor(1))
  elsif sec < 60
    t 'good_job.duration.seconds', sec: sec.floor
  elsif sec < 3600
    t 'good_job.duration.minutes', min: (sec / 60).floor, sec: (sec % 60).floor
  else
    t 'good_job.duration.hours', hour: (sec / 3600).floor, min: ((sec % 3600) / 60).floor
  end
end

#number_to_human(count) ⇒ Object



33
34
35
# File 'app/helpers/good_job/application_helper.rb', line 33

def number_to_human(count)
  super(count, **translate_hash("good_job.number.human.decimal_units"))
end

#number_with_delimiter(count) ⇒ Object



37
38
39
# File 'app/helpers/good_job/application_helper.rb', line 37

def number_with_delimiter(count)
  super(count, **translate_hash('good_job.number.format'))
end

#relative_time(timestamp, **options) ⇒ Object



27
28
29
30
31
# File 'app/helpers/good_job/application_helper.rb', line 27

def relative_time(timestamp, **options)
  options = options.reverse_merge({ scope: "good_job.datetime.distance_in_words" })
  text = t("good_job.helpers.relative_time.#{timestamp.future? ? 'future' : 'past'}", time: time_ago_in_words(timestamp, **options))
  tag.time(text, datetime: timestamp, title: timestamp)
end

#translate_hash(key, **options) ⇒ Object



41
42
43
# File 'app/helpers/good_job/application_helper.rb', line 41

def translate_hash(key, **options)
  translation_exists?(key, **options) ? translate(key, **options) : {}
end

#translation_exists?(key, **options) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/helpers/good_job/application_helper.rb', line 45

def translation_exists?(key, **options)
  I18n.exists?(scope_key_by_partial(key), **options)
end