OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/models/exports/formatters/custom_field.rb

30 lines
726 B

module Exports
module Formatters
class CustomField < Default
##
# Checks if this column is applicable for this column
def self.apply?(attribute)
attribute.start_with?('cf_')
end
##
# Takes a WorkPackage and an attribute and returns the value to be exported.
def format(object, **)
return '' if custom_field.nil?
object.formatted_custom_value_for(custom_field)
end
##
# Finds a custom field from the attribute identifier
def custom_field
unless defined?(@custom_field)
@custom_field = ::CustomField.find_by(id: attribute.to_s.sub('cf_', '').to_i)
end
@custom_field
end
end
end
end