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



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

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

  publisher == other.publisher && copublisher == other.copublisher
end

#bodyObject



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

def body
  publisher
end

#copublished?Boolean

Returns:

  • (Boolean)


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

def copublished?
  copublisher&.any?
end

#eql?(other) ⇒ Boolean

Checks equality using hash for consistency

Parameters:

  • other (Object)

    object to compare with

Returns:

  • (Boolean)

    true if equal



54
55
56
# File 'lib/pubid/iso/components/publisher.rb', line 54

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

#has_copublisher?Boolean

Returns:

  • (Boolean)


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

def has_copublisher?
  copublisher&.any?
end

#hashInteger

Note:

Memoized for performance

Returns hash code for publisher component

Returns:

  • (Integer)

    hash code



47
48
49
# File 'lib/pubid/iso/components/publisher.rb', line 47

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

#render(context: nil) ⇒ Object



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

def render(context: nil)
  return publisher unless copublisher&.any?

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

#to_sObject



24
25
26
27
28
# File 'lib/pubid/iso/components/publisher.rb', line 24

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