Class: TableHelpers::DateFormatter

Inherits:
SimpleFormatter show all
Defined in:
app/utils/table_helpers.rb

Constant Summary collapse

DATE =
'%d.%m.%Y'

Instance Method Summary collapse

Constructor Details

#initialize(default_format) ⇒ DateFormatter

Returns a new instance of DateFormatter.



44
45
46
# File 'app/utils/table_helpers.rb', line 44

def initialize(default_format)
  @default_format = default_format
end

Instance Method Details

#format_value(item, format) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/utils/table_helpers.rb', line 48

def format_value(item, format)
  if item
    item = item.localtime if item.respond_to?(:localtime)
    case format
      when String
        Russian::strftime(item, format)
      when Proc
        format.call(item)
      when :date
        Russian::strftime(item, DATE)
      else
        Russian::strftime(item, @default_format)
    end
  else
    ''
  end
end