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)

Instance Method Summary collapse

Instance Method Details

#eql?(other) ⇒ Boolean

Checks equality with another stage component

Parameters:

  • other (Object)

    object to compare with

Returns:

  • (Boolean)

    true if equal



47
48
49
50
51
# File 'lib/pubid/components/stage.rb', line 47

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

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

#hashInteger

Note:

Memoized for performance

Returns hash code for stage component

Returns:

  • (Integer)

    hash code



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

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

#render(context: nil) ⇒ Object



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

def render(context: nil)
  abbr.to_s
end

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

Render stage with optional context for flavor-specific separators

Parameters:

  • context (RenderingContext) (defaults to: nil)

    rendering context for flavor rules

  • has_copublisher (Boolean) (defaults to: false)

    whether identifier has copublisher

Returns:

  • (String)

    rendered stage string



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pubid/components/stage.rb', line 21

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
    # Default behavior: space after copublisher, slash otherwise
    has_copublisher ? " #{abbr}" : "/#{abbr}"
  end
end