Class: Pubid::Cie::Components::Language

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

Overview

Language component for CIE identifiers Handles three distinct language formats:

  1. Slash-prefix: /E, /F, /G (legacy, no year)

  2. Slash with colon and year: /E:2001 (slash_colon)

  3. Parenthetical: (DE), (ES), (en)

  4. Translation year: (RU-2021)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(lang_str) ⇒ Object

Parse language string with format detection



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pubid/cie/components/language.rb', line 35

def self.parse(lang_str)
  return nil if lang_str.nil? || lang_str.strip.empty?

  # Detect slash format
  if lang_str.start_with?("/")
    new(code: lang_str[1..], format: "slash")
  # Detect paren with year
  elsif lang_str.match?(/\(([A-Z]{2})-(\d{4})\)/)
    match = lang_str.match(/\(([A-Z]{2})-(\d{4})\)/)
    new(code: match[1], translation_year: match[2],
        format: "paren_year")
  # Detect simple paren
  elsif lang_str.match?(/\(([A-Za-z]{2,3})\)/)
    match = lang_str.match(/\(([A-Za-z]{2,3})\)/)
    new(code: match[1], format: "paren")
  else
    # Default: treat as code
    new(code: lang_str, format: "paren")
  end
end

Instance Method Details

#to_sObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pubid/cie/components/language.rb', line 19

def to_s
  case format
  when "slash"
    "/#{code}"                          # /E, /F, /G (no year)
  when "slash_colon"
    "/#{code}"                          # /E (colon and year handled by Identical)
  when "paren"
    "(#{code})"                         # (DE), (ES), (en)
  when "paren_year"
    " (#{code}-#{translation_year})" # (RU-2021)
  else
    "(#{code})" # Default to paren
  end
end