module ExcelSerializer::HeadersTranslator

Public Instance Methods

compute_headers() click to toggle source
# File lib/excel_serializer/headers_translator.rb, line 6
def compute_headers
  if computed_headers.blank?
    self.computed_headers ||= []
    self.attributes_to_serialize.each do |attribute|
      self.computed_headers << translate_attribute(attribute)
    end
  end
  computed_headers
end
headers() click to toggle source
# File lib/excel_serializer/headers_translator.rb, line 46
def headers
  @headers ||= compute_headers
end
humanize(attribute) click to toggle source
# File lib/excel_serializer/headers_translator.rb, line 35
def humanize(attribute)
  attribute.to_s.humanize
end
i18n_translation(attribute) click to toggle source
# File lib/excel_serializer/headers_translator.rb, line 31
def i18n_translation(attribute)
  I18n.t("#{translation_base}.#{attribute}")
end
translate_attribute(attribute) click to toggle source
# File lib/excel_serializer/headers_translator.rb, line 20
def translate_attribute(attribute)
  case self.current_config.translation_adapter
  when :i18n
    i18n_translation(attribute)
  when :humanize
    humanize(attribute)
  else
    raise "Invalid translations adapter"
  end
end
translation_base() click to toggle source
# File lib/excel_serializer/headers_translator.rb, line 39
def translation_base
  return @translation_key_base if @translation_key_base.present?
  obj_name = self.name.sub('ExcelSerializer','').underscore
  @translation_key_base = "activerecord.attributes.#{obj_name}"
end
translation_key_base(translation_key_base) click to toggle source
# File lib/excel_serializer/headers_translator.rb, line 16
def translation_key_base(translation_key_base)
  @translation_key_base = translation_key_base
end