Module: RBoss::Formatters

Defined in:
lib/rboss/view/formatters.rb

Overview

A module that holds the formatters

Class Method Summary collapse

Class Method Details

.array(separator = ', ') ⇒ Object



40
41
42
43
44
# File 'lib/rboss/view/formatters.rb', line 40

def array(separator = ', ')
  Yummi::to_format do |ctx|
    ctx.value.join separator
  end
end

.date(format = '%d-%m-%Y %H:%M:%S %z') ⇒ Object



11
12
13
14
15
16
# File 'lib/rboss/view/formatters.rb', line 11

def date(format = '%d-%m-%Y %H:%M:%S %z')
  Yummi::to_format do |ctx|
    value = ctx.value
    Time.at(value / 1000).strftime(format)
  end
end

.timeObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/rboss/view/formatters.rb', line 18

def time
  Yummi::to_format do |ctx|
    value = ctx.value / 1000
    seconds = value % 60
    minutes = (value / 60) % 60
    hours = (value / 60 / 60) % 24
    days = (value / 60 / 60 / 24)
    "#{days}d #{hours}h #{minutes}m #{seconds}s"
  end
end

.trim(max) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/rboss/view/formatters.rb', line 29

def trim(max)
  Yummi::to_format do |ctx|
    value = ctx.value.to_s
    if value.size > max
      value[0..max] << '...'
    else
      value
    end
  end
end