module SoftwareResponseBuilder
  private

  def build_response(software, releases)
    sorted       = releases.sort_by { |r| r.created_at || Time.at(0) }.reverse
    latest       = sorted.reject { |r| r.version.to_s.start_with?("dev-") }.first
    web_playable = sorted.find   { |r| r.html_folder_path.present? }

    SoftwareDetailSerializer.render_as_hash(software,
      releases:    sorted,
      latest:      latest,
      web_playable: web_playable
    )
  end
end
