require "devops-client/output/base"

module Output
  class Key < Base

    def table
      title = I18n.t("output.title.key.list")
      headers, rows = create(@data)
      create_table headers, rows, title
    end

    def csv
      headers, rows = create(@data)
      create_csv headers, rows
    end

  private
    def create list
      abort(I18n.t("output.not_found.key.list")) if list.nil? or list.empty?
      rows = []
      list.each {|l| rows.push  [ l["id"], l["filename"], time_to_s(l["created_at"]) ] }
      return [ I18n.t("output.table_header.id"), I18n.t("output.table_header.filename"), I18n.t("output.table_header.created_at") ], rows
    end
  end
end
