class DataDisplay::Actions::Display

Attributes

format[R]
raw_value[R]

Public Class Methods

new(raw_value, format) click to toggle source
# File lib/data_display/actions.rb, line 10
def initialize(raw_value, format)
  @raw_value = raw_value
  @format = format && format.to_sym
end

Public Instance Methods

value() click to toggle source
# File lib/data_display/actions.rb, line 15
def value
  respond_to?(method_name, true) ? send(method_name) : raw_value
end

Private Instance Methods

class_name() click to toggle source
# File lib/data_display/actions.rb, line 77
def class_name
  raw_value.class.name.underscore
end
date_display() click to toggle source
# File lib/data_display/actions.rb, line 49
def date_display
  localize
end
date_time_display() click to toggle source
# File lib/data_display/actions.rb, line 57
def date_time_display
  localize
end
false_class_display() click to toggle source
# File lib/data_display/actions.rb, line 24
def false_class_display
  translate
end
fixnum_display() click to toggle source
# File lib/data_display/actions.rb, line 28
def fixnum_display
  number_display
end
fixnum_format() click to toggle source
# File lib/data_display/actions.rb, line 93
def fixnum_format
  format || :delimiter
end
float_display() click to toggle source
# File lib/data_display/actions.rb, line 32
def float_display
  number_display
end
locale_format() click to toggle source
# File lib/data_display/actions.rb, line 81
def locale_format
  format || :long
end
localize() click to toggle source
# File lib/data_display/actions.rb, line 73
def localize
  I18n.localize raw_value, format: localize_format, scope: :data_display
end
localize_format() click to toggle source
# File lib/data_display/actions.rb, line 85
def localize_format
  format || :long
end
method_name() click to toggle source
# File lib/data_display/actions.rb, line 65
def method_name
  "#{class_name}_display"
end
nil_class_display() click to toggle source
# File lib/data_display/actions.rb, line 45
def nil_class_display
  translate
end
number_display() click to toggle source
# File lib/data_display/actions.rb, line 36
def number_display
  case fixnum_format
  when :delimiter
    number_with_delimiter raw_value
  when :currency
    number_to_currency raw_value
  end
end
string_display() click to toggle source
# File lib/data_display/actions.rb, line 61
def string_display
  truncate(raw_value, length: string_length)
end
string_format() click to toggle source
# File lib/data_display/actions.rb, line 89
def string_format
  format || :long
end
string_length() click to toggle source
# File lib/data_display/actions.rb, line 97
def string_length
  case string_format
  when :short
    60
  when :long
    180
  else
    raw_value.length
  end
end
time_display() click to toggle source
# File lib/data_display/actions.rb, line 53
def time_display
  localize
end
translate() click to toggle source
# File lib/data_display/actions.rb, line 69
def translate
  I18n.translate "data_display.#{class_name}.formats.#{locale_format}"
end
true_class_display() click to toggle source
# File lib/data_display/actions.rb, line 20
def true_class_display
  translate
end