Class: Mods::Date::EdtfFormat

Inherits:
Mods::Date show all
Defined in:
lib/mods/date.rb

Overview

Strict EDTF parser

Instance Attribute Summary collapse

Attributes inherited from Mods::Date

#xml

Class Method Summary collapse

Methods inherited from Mods::Date

#approximate?, #as_range, #encoding, #encoding?, #end?, from_element, #inferred?, #initialize, #key?, parse_date, #point, #precision, #qualifier, #questionable?, #single?, #start?, #text, #to_a, #type

Constructor Details

This class inherits a constructor from Mods::Date

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



66
67
68
# File 'lib/mods/date.rb', line 66

def date
  @date
end

Class Method Details

.normalize_to_edtf(text) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mods/date.rb', line 68

def self.normalize_to_edtf(text)
  return '0000' if text.strip == '0'

  case text
  when /^\d{1,3}$/
    text.rjust(4, "0") if text =~ /^\d{1,3}$/
  when /^-\d{1,3}$/
    "-#{text.sub(/^-/, '').rjust(4, "0")}"
  else
    text
  end
end