<commit_before>require 'stash/wrapper'

module Stash
  module Wrapper
    class StashWrapperBuilder
      attr_reader :dcs_resource
      attr_reader :uploads
      attr_reader :version_number

      def initialize(dcs_resource:, version_number:, uploads:)
        @dcs_resource = dcs_resource
        @version_number = version_number
        @uploads = uploads
      end

      def build_stash_wrapper
        StashWrapper.new(
          identifier: to_sw_identifier(dcs_resource.identifier),
          version: Version.new(number: version_number, date: Date.today),
          license: to_sw_license(dcs_resource.rights_list),
          inventory: to_sw_inventory(uploads),
          descriptive_elements: [dcs_resource.save_to_xml]
        )
      end

      def build_xml
        build_stash_wrapper.write_xml
      end

      private

      def to_sw_identifier(dcs_identifier)
        return unless dcs_identifier
        raise "Invalid identifier type; expected DOI, was #{dcs_identifier.identifier_type}" unless dcs_identifier.identifier_type == 'DOI'
        Identifier.new(type: IdentifierType::DOI, value: dcs_identifier.value)
      end

      def to_sw_license(dcs_rights_list)
        return unless dcs_rights_list && !dcs_rights_list.empty?
        dcs_rights = dcs_rights_list[0]
        License.new(name: dcs_rights.value, uri: dcs_rights.uri)
      end

      def to_sw_inventory(uploads)
        return unless uploads && !uploads.empty?
        Inventory.new(files: uploads.map { |upload| to_stash_file(upload) })
      end

      def to_stash_file(upload)
        StashFile.new(
          pathname: upload[:name],
          size_bytes: upload[:size],
          mime_type: upload[:type]
        )
      end<commit_msg>Create inventory even when file list is empty<commit_after>require 'stash/wrapper'

module Stash
  module Wrapper
    class StashWrapperBuilder
      attr_reader :dcs_resource
      attr_reader :uploads
      attr_reader :version_number

      def initialize(dcs_resource:, version_number:, uploads:)
        @dcs_resource = dcs_resource
        @version_number = version_number
        @uploads = uploads
      end

      def build_stash_wrapper
        StashWrapper.new(
          identifier: to_sw_identifier(dcs_resource.identifier),
          version: Version.new(number: version_number, date: Date.today),
          license: to_sw_license(dcs_resource.rights_list),
          inventory: to_sw_inventory(uploads),
          descriptive_elements: [dcs_resource.save_to_xml]
        )
      end

      def build_xml
        build_stash_wrapper.write_xml
      end

      private

      def to_sw_identifier(dcs_identifier)
        return unless dcs_identifier
        raise "Invalid identifier type; expected DOI, was #{dcs_identifier.identifier_type}" unless dcs_identifier.identifier_type == 'DOI'
        Identifier.new(type: IdentifierType::DOI, value: dcs_identifier.value)
      end

      def to_sw_license(dcs_rights_list)
        return unless dcs_rights_list && !dcs_rights_list.empty?
        dcs_rights = dcs_rights_list[0]
        License.new(name: dcs_rights.value, uri: dcs_rights.uri)
      end

      def to_sw_inventory(uploads)
        return unless uploads
        Inventory.new(files: uploads.map { |upload| to_stash_file(upload) })
      end

      def to_stash_file(upload)
        StashFile.new(
          pathname: upload[:name],
          size_bytes: upload[:size],
          mime_type: upload[:type]
        )
      end
{'fraction_non_alphanumeric': 0.07431850789096127, 'fraction_numerical': 0.0005738880918220947, 'mean_word_length': 2.744360902255639, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5097139', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1039, 'n_words': 209}