Class: Pubid::Iso::Components::Publisher

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/pubid/iso/components/publisher.rb

Overview

ISO Publisher with copublisher support Examples: ISO, ISO/IEC, ISO/IEC/IEEE

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/pubid/iso/components/publisher.rb', line 42

def ==(other)
  return false unless other.is_a?(Publisher)

  # copublisher is a collection: parsing yields [] while building via
  # .create (e.g. from an index hash) leaves it nil. Treat the empty
  # collection and "no collection" as equal so both forms compare.
  publisher == other.publisher &&
    copublisher.to_a == other.copublisher.to_a
end

#bodyObject



14
15
16
# File 'lib/pubid/iso/components/publisher.rb', line 14

def body
  publisher
end

#copublished?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/pubid/iso/components/publisher.rb', line 38

def copublished?
  copublisher&.any?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/pubid/iso/components/publisher.rb', line 56

def eql?(other)
  hash == other.hash && self == other
end

#has_copublisher?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/pubid/iso/components/publisher.rb', line 34

def has_copublisher?
  copublisher&.any?
end

#hashObject



52
53
54
# File 'lib/pubid/iso/components/publisher.rb', line 52

def hash
  @hash ||= [publisher, copublisher.to_a].map(&:hash).hash
end

#render(context: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/pubid/iso/components/publisher.rb', line 18

def render(context: nil)
  if context&.urn?
    return publisher&.downcase
  end

  return publisher unless copublisher&.any?

  publisher + copublisher.map { |cp| "/#{cp}" }.join
end

#to_sObject



28
29
30
31
32
# File 'lib/pubid/iso/components/publisher.rb', line 28

def to_s
  result = publisher
  result += copublisher.map { |cp| "/#{cp}" }.join if copublisher&.any?
  result
end