Module: Pubid::Cie::Identifiers::CodeAttributes
- Included in:
- DualPublished, Identical, JointPublished, Standard
- Defined in:
- lib/pubid/cie/identifiers/code_attributes.rb
Overview
Shared document-code attributes + rendering for the CIE identifier types that carry a code (Standard, Identical, JointPublished, DualPublished).
The code fields live flat on the identifier (no nested Components::Code), so the serialized hash stays compact:
{style:, year:, ..., number: "018", iteration: "2"}
rather than nesting them under a code: iteration:, style:.
code.style is intentionally gone: it always equalled the identifier's
own style (the builder set both from one value), so #code_string reads
the identifier's style directly for the part-separator fallback.
Class Method Summary collapse
Instance Method Summary collapse
-
#code_string ⇒ Object
Render the code portion: "018.2", "170-1", "19/2.1", "11664-1".
Class Method Details
.included(base) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/pubid/cie/identifiers/code_attributes.rb', line 19 def self.included(base) base.class_eval do attribute :number, :string # "018", "170", "11664" attribute :part, :string # "1", "2", "4" attribute :iteration, :string # "2" in "018.2" attribute :part_separator, :string # "slash" | "dash" (original sep) end end |
Instance Method Details
#code_string ⇒ Object
Render the code portion: "018.2", "170-1", "19/2.1", "11664-1".
Uses part_separator when set, otherwise falls back to the
identifier's style (legacy -> "/", current -> "-").
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pubid/cie/identifiers/code_attributes.rb', line 31 def code_string return nil unless number result = number.dup if part && iteration result += "/#{part}.#{iteration}" elsif iteration result += ".#{iteration}" elsif part separator = case part_separator when "slash" then "/" when "dash" then "-" else style == "current" ? "-" : "/" end result += "#{separator}#{part}" end result end |