Class: RelatonIso::DocumentIdentifier

Inherits:
RelatonBib::DocumentIdentifier
  • Object
show all
Defined in:
lib/relaton_iso/document_identifier.rb

Instance Method Summary collapse

Instance Method Details

#all_partsObject



29
30
31
# File 'lib/relaton_iso/document_identifier.rb', line 29

def all_parts
  @all_parts = true
end

#idObject

rubocop:disable Metrics/MethodLength



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/relaton_iso/document_identifier.rb', line 3

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

#remove_dateObject



25
26
27
# File 'lib/relaton_iso/document_identifier.rb', line 25

def remove_date
  @id.year = nil
end

#remove_partObject



21
22
23
# File 'lib/relaton_iso/document_identifier.rb', line 21

def remove_part
  @id.part = nil
end

#stringify(val) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/relaton_iso/document_identifier.rb', line 37

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

#stringify_values(hash) ⇒ Object



33
34
35
# File 'lib/relaton_iso/document_identifier.rb', line 33

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

#to_hObject



17
18
19
# File 'lib/relaton_iso/document_identifier.rb', line 17

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