Class: Identifier::Global::Lccn

Inherits:
Identifier::Global show all
Defined in:
app/models/identifier/global/lccn.rb

Overview

TODO:

This validation will be needing a lot of additional work, if we start relying on it. See www.loc.gov/marc/bibliographic/bd010.html

LCCN Structure A (1898-2000)

Name of Element 	Number of characters 	Character position in field
Alphabetic prefix 	        3 	          00-02
Year 	                      2 	          03-04
Serial number 	            6 	          05-10
Supplement number 	        1 	          11
Suffix and/or Revision Date variable 	    12-n

LCCN Structure B (2001- )

Name of Element 	Number of characters 	Character position in field
Alphabetic prefix   2 	                    00-01
Year                4 	                    02-05
Serial number 	    6 	                    06-11

Alphabetic prefix

Prefixes are carried in a MARC record as lowercase alphabetic characters and serve to differentiate
  between different series of LC control numbers. Prefixes are left justified and unused positions
  contain blanks. If no prefix is present, the prefix portion contains blanks.

Constant Summary

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Constants included from Shared::DualAnnotator

Shared::DualAnnotator::ALWAYS_COMMUNITY

Instance Attribute Summary

Attributes inherited from Identifier::Global

#relation

Attributes inherited from Identifier

#cached, #cached_numeric_identifier, #identifier, #identifier_object_id, #namespace_id, #project_id, #type

Instance Method Summary collapse

Methods inherited from Identifier::Global

#build_cached, #dwc_occurrences, #is_global?, #sv_resolves?

Methods included from SoftValidation

#clear_soft_validations, #fix_for, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations, #soft_validators

Methods inherited from Identifier

#build_cached, #build_cached_numeric_identifier, #is_global?, #is_local?, prototype_identifier, #set_cached, #type_name

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::Labels

#labeled?

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from Shared::PolymorphicAnnotator

#annotated_object_is_persisted?

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Method Details

#using_iccn_classObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/identifier/global/lccn.rb', line 25

def using_iccn_class
  unless identifier.nil?
    lccn = identifier

    # '200112345', '2010549727', '2003064850', '|a  2003064850', '88156495', '68-004897', '2001-459440'

    #   LCCN Structure A (1898-2000)
    /^(?<preamble_a>.{3}){0,1}(?<year_a>\d{2})-{0,1}(?<serial_a>\d{6})(?<supplement>\d){0,1}(?<suffix>.*)$/i =~ lccn
    #   LCCN Structure B (2001- )
    # this regex should be good for all of the third millennium
    /^(?<preamble_b>.{2}){0,1}(?<year_b>\d{4})-{0,1}(?<serial_b>\d{6})$/i =~ lccn

    century = '19'
    unless year_a.nil?
      serial = serial_a.to_i
      case year_a
        when '98'
          if serial < 3000
            century = '18'
          end
        when '99'
          if serial < 6000
            century = '18'
          end
        when '00'
          if serial >= 8000
            century = '20'
          end
      end
      year = century + year_a
      return
    end

    return unless (year_b.nil? or serial_b.nil?)

    unless year_b.nil?
      year = year_b.to_i
      if (year > Time.now.year) or (year < 2001)
        errors.add(:identifier, "'#{identifier}' is too far in the future, or before 2001.")
        return
      end
    else
      if serial_b.nil?
        errors.add(:identifier, "'#{identifier}' is an improperly formed LCCN.")
        return
      end
    end
  end
end