Class: RDF::Literal::EDTF
- Inherits:
-
RDF::Literal
- Object
- RDF::Literal
- RDF::Literal::EDTF
- 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
-
#approximate? ⇒ Boolean
Returns true if this is an approximate date.
-
#canonicalize ⇒ String
Returns the canonical string representation.
-
#humanize ⇒ String
Converts to a human-readable string.
-
#initialize(value, datatype: nil, lexical: nil, **options) ⇒ EDTF
constructor
A new instance of EDTF.
-
#interval? ⇒ Boolean
Returns true if this is an interval.
-
#object ⇒ EDTF::Date, ...
(also: #to_edtf)
Returns the EDTF object value.
-
#season? ⇒ Boolean
Returns true if this is a season.
-
#set? ⇒ Boolean
Returns true if this is a set.
-
#uncertain? ⇒ Boolean
Returns true if this is an uncertain date.
-
#valid? ⇒ Boolean
Validates the EDTF literal.
Constructor Details
#initialize(value, datatype: nil, lexical: nil, **options) ⇒ EDTF
Returns a new instance of EDTF.
26 27 28 29 30 31 32 33 |
# File 'lib/solis/rdf_edtf_literal.rb', line 26 def initialize(value, datatype: nil, lexical: nil, **) @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, **) end |
Instance Method Details
#approximate? ⇒ Boolean
Returns true if this is an approximate date
89 90 91 |
# File 'lib/solis/rdf_edtf_literal.rb', line 89 def approximate? @edtf_value.respond_to?(:approximate?) && @edtf_value.approximate? end |
#canonicalize ⇒ String
Returns the canonical string representation
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 |
#humanize ⇒ String
Converts to a human-readable 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
97 98 99 |
# File 'lib/solis/rdf_edtf_literal.rb', line 97 def interval? @edtf_value.is_a?(::EDTF::Interval) end |
#object ⇒ EDTF::Date, ... Also known as: to_edtf
Returns the EDTF object value
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
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
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
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
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 |