Class: Pubid::Components::Stage

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

Overview

Stage component (a set of defined stages)

Human render: abbreviation with flavor-specific separator. URN render: stage abbreviation alone (no separator).

Instance Method Summary collapse

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(other)
  return false unless other.is_a?(self.class)

  stage_code == other.stage_code && abbr == other.abbr
end

#hashObject



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

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

#render(context: nil) ⇒ Object



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

def render(context: nil)
  return abbr.to_s if context&.urn?

  abbr.to_s
end

#to_s(context: nil, has_copublisher: false) ⇒ Object



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

def to_s(context: nil, has_copublisher: false)
  return "" unless abbr

  if context
    sep = context.stage_separator_for(has_copublisher:)
    sep == "" ? abbr : "#{sep}#{abbr}"
  else
    has_copublisher ? " #{abbr}" : "/#{abbr}"
  end
end