Module: DecoratorDryer::Formatters

Includes:
ActionView::Helpers::NumberHelper
Included in:
Shortcuts
Defined in:
lib/decorator_dryer/formatters.rb

Instance Method Summary collapse

Instance Method Details

#format_date(date) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/decorator_dryer/formatters.rb', line 7

def format_date(date)
  if context[:humanize]
    date_format = DecoratorDryer.configuration.humanized_date_format
  else
    date_format = DecoratorDryer.configuration.date_format
  end
  date.try(:strftime, date_format)
end

#format_datetime(datetime) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/decorator_dryer/formatters.rb', line 21

def format_datetime(datetime)
  if context[:humanize]
    datetime_format = DecoratorDryer.configuration.humanized_datetime_format
  else
    datetime_format = DecoratorDryer.configuration.datetime_format
  end
  datetime.try(:strftime, datetime_format)
end

#format_precision_number(number, precision = 0) ⇒ Object



30
31
32
33
34
35
# File 'lib/decorator_dryer/formatters.rb', line 30

def format_precision_number(number, precision = 0)
  return 0.0 if number.blank?
  return number.to_d if precision < 1

  number_with_precision(number, precision: precision)
end

#format_time(time) ⇒ Object



16
17
18
19
# File 'lib/decorator_dryer/formatters.rb', line 16

def format_time(time)
  time_format = DecoratorDryer.configuration.time_format
  time.try(:strftime, time_format)
end

#to_name(association) ⇒ Object



37
38
39
# File 'lib/decorator_dryer/formatters.rb', line 37

def to_name(association)
  association.try(:name)
end