rosa-build/app/presenters/api/v1/repository_package_presente...

44 lines
916 B
Ruby
Raw Normal View History

require 'csv'
2016-03-20 09:24:23 +00:00
class Api::V1::RepositoryPackagePresenter
CSV_HEADERS = {
project_owner: 'Project owner',
project_name: 'Project name',
package_name: 'Package name',
epoch: 'Epoch',
version: 'Version',
release: 'Release',
maintainer_uname: 'Maintainer uname',
2016-03-20 09:24:23 +00:00
maintainer_email: 'Maintainer email'
}
attr_reader :package
delegate *%i(project name epoch version release assignee build_list), to: :package
def initialize(package)
@package = package
end
def to_csv_row
CSV::Row.new(
CSV_HEADERS.keys,
[
project.owner_uname,
project.name,
name,
epoch,
version,
release,
assignee.uname,
2016-03-20 09:24:23 +00:00
assignee.email
]
)
end
def self.csv_header
# Using ruby's built-in CSV::Row class
# true - means its a header
CSV::Row.new CSV_HEADERS.keys, CSV_HEADERS.values, true
end
end