Class: StaticTextFormatter

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/static_text_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ StaticTextFormatter

Returns a new instance of StaticTextFormatter.



3
4
5
6
# File 'app/helpers/static_text_formatter.rb', line 3

def initialize(object)
  @object = object
  @columns = @object.class.columns.index_by(&:name).with_indifferent_access
end

Instance Method Details

#format(method) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/static_text_formatter.rb', line 8

def format(method)
  method_value = @object.send(method)
  if method_value
    if @columns[method]
      method_type = @columns[method].type
      if method_type == :datetime
        method_value = method_value.localtime if method_value.respond_to?(:localtime)
        Russian.strftime(method_value, '%d.%m.%Y %H:%M')
      else
        method_value
      end
    else
      method_value
    end
  end
end