Class: RDF::Literal::EDTF

Inherits:
RDF::Literal show all
Defined in:
lib/solis/rdf_edtf_literal.rb

Overview

Extended Date/Time Format (EDTF) literal for RDF 3.x

This class provides RDF literal support for EDTF dates, implementing the Library of Congress Extended Date/Time Format specification.

Constant Summary collapse

DATATYPE =
RDF::URI('http://id.loc.gov/datatypes/edtf')
GRAMMAR =

Grammar pattern for EDTF validation Supports Level 0, 1, and 2 expressions This is a simplified pattern - the edtf gem handles full validation

/^[\d\-\/\?\~\.\[\]\{\}XuU\^%\,\+\:\s]+$/

Instance Method Summary collapse

Constructor Details

#initialize(value, datatype: nil, lexical: nil, **options) ⇒ EDTF

Returns a new instance of EDTF.

Parameters:

  • value (Object)
  • options (Hash{Symbol => Object})

Options Hash (**options):

  • :lexical (String) — default: nil


26
27
28
29
30
31
32
33
# File 'lib/solis/rdf_edtf_literal.rb', line 26

def initialize(value, datatype: nil, lexical: nil, **options)
  @edtf_value = parse_edtf(value)

  # Use EDTF string representation as the lexical form
  lexical_value = @edtf_value.respond_to?(:edtf) ? @edtf_value.edtf : value.to_s

  super(lexical_value, datatype: DATATYPE, lexical: lexical, **options)
end

Instance Method Details

#approximate?Boolean

Returns true if this is an approximate date

Returns:

  • (Boolean)


89
90
91
# File 'lib/solis/rdf_edtf_literal.rb', line 89

def approximate?
  @edtf_value.respond_to?(:approximate?) && @edtf_value.approximate?
end

#canonicalizeString

Returns the canonical string representation

Returns:

  • (String)


61
62
63
64
# File 'lib/solis/rdf_edtf_literal.rb', line 61

def canonicalize
  return self if @edtf_value.nil?
  self.class.new(@edtf_value.edtf)
end

#humanizeString

Converts to a human-readable string

Returns:

  • (String)


70
71
72
73
74
75
# File 'lib/solis/rdf_edtf_literal.rb', line 70

def humanize
  return to_s unless @edtf_value.respond_to?(:humanize)
  @edtf_value.humanize
rescue
  to_s
end

#interval?Boolean

Returns true if this is an interval

Returns:

  • (Boolean)


97
98
99
# File 'lib/solis/rdf_edtf_literal.rb', line 97

def interval?
  @edtf_value.is_a?(::EDTF::Interval)
end

#objectEDTF::Date, ... Also known as: to_edtf

Returns the EDTF object value

Returns:

  • (EDTF::Date, EDTF::Interval, EDTF::Season, EDTF::Set, etc.)


39
40
41
# File 'lib/solis/rdf_edtf_literal.rb', line 39

def object
  @edtf_value
end

#season?Boolean

Returns true if this is a season

Returns:

  • (Boolean)


105
106
107
# File 'lib/solis/rdf_edtf_literal.rb', line 105

def season?
  @edtf_value.is_a?(::EDTF::Season)
end

#set?Boolean

Returns true if this is a set

Returns:

  • (Boolean)


113
114
115
# File 'lib/solis/rdf_edtf_literal.rb', line 113

def set?
  @edtf_value.is_a?(::EDTF::Set)
end

#uncertain?Boolean

Returns true if this is an uncertain date

Returns:

  • (Boolean)


81
82
83
# File 'lib/solis/rdf_edtf_literal.rb', line 81

def uncertain?
  @edtf_value.respond_to?(:uncertain?) && @edtf_value.uncertain?
end

#valid?Boolean

Validates the EDTF literal

Returns:

  • (Boolean)


49
50
51
52
53
54
55
# File 'lib/solis/rdf_edtf_literal.rb', line 49

def valid?
  return false if @edtf_value.nil?
  # EDTF values are valid if they were successfully parsed
  true
rescue
  false
end