Module: MakeExportable::InstanceMethods

Defined in:
lib/make_exportable/core.rb

Instance Method Summary collapse

Instance Method Details

#export_attribute(attribute) ⇒ Object

export_attribute returns the export value of an attribute or method. By default, this is simply the value of the attribute or method itself, but the value can be permanently overridden with another value by defining a method called “#attribute_export”. The alternate method will always be called in place of the original one. At a minimum, this is useful when a date should be formatted when exporting or when booleans should always export as “Yes”/“No”. But it can do more, performing any amount of processing or additional queries, as long as in the end it returns a value for the export to use. Sending an attribute name that does not exist will return an empty string.



296
297
298
299
300
301
302
303
304
305
306
# File 'lib/make_exportable/core.rb', line 296

def export_attribute(attribute)
  begin
    if self.respond_to?("#{attribute}_export")
      return self.send("#{attribute}_export").to_s
    else
      return self.send(attribute).to_s
    end
  rescue
    return ""
  end
end