Sha256: da7f64b771a5cdc9469bca0b41ef1c86e8e44fbb6b2383d7016a9699473a91ef

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module RelatonIso
  class DocumentIdentifier < RelatonBib::DocumentIdentifier
    def id # rubocop:disable Metrics/MethodLength
      id_str = @id.to_s.sub(/\sED\d+/, "").squeeze(" ").sub(/^ISO\/\s/, "ISO ") # workarounds for pubid gem bugs
      if @all_parts
        if type == "URN"
          return "#{@id.urn}:ser"
        else
          return "#{id_str} (all parts)"
        end
      end
      type == "URN" ? @id.urn.to_s : id_str
    rescue Pubid::Iso::Errors::NoEditionError => e
      Util.warn "#{type} identifier can't be generated for `#{@id}`: #{e.message}"
    end

    def to_h
      stringify_values(@id.to_h) if @id.respond_to? :to_h
    end

    def remove_part
      @id.part = nil
    end

    def remove_date
      @id.year = nil
    end

    def all_parts
      @all_parts = true
    end

    def stringify_values(hash)
      hash.transform_values { |v| stringify(v) }.reject { |_k, v| v.empty? }
    end

    def stringify(val)
      case val
      when Array then val.map { |i| i.is_a?(Hash) ? stringify_values(i) : i.to_s }
      when Hash then stringify_values(val)
      when Symbol then val
      else val.to_s
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
relaton-iso-1.20.0 lib/relaton_iso/document_identifier.rb
relaton-iso-1.19.2 lib/relaton_iso/document_identifier.rb
relaton-iso-1.19.1 lib/relaton_iso/document_identifier.rb
relaton-iso-1.19.0 lib/relaton_iso/document_identifier.rb