Class: RDF::Literal::YearMonth

Inherits:
Date
  • Object
show all
Defined in:
lib/rdf/xsd/date.rb

Overview

gYearMonth represents a specific gregorian month in a specific gregorian year. The value space of gYearMonth is the set of Gregorian calendar months as defined in ยง 5.2.1 of [ISO 8601]. Specifically, it is a set of one-month long, non-periodic instances e.g. 1999-10 to represent the whole month of 1999-10, independent of how many days this month has.

Constant Summary collapse

DATATYPE =
RDF::XSD.gYearMonth
GRAMMAR =
%r(\A(-?\d{4,}-\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|Z)?\Z).freeze
FORMAT =
'%Y-%m'.freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of YearMonth.



29
30
31
32
33
# File 'lib/rdf/xsd/date.rb', line 29

def initialize(value, datatype: nil, lexical: nil, **options)
  @string = lexical || value.to_s
  object = GRAMMAR.match(value.to_s) && ::Date.parse("#{$1}-01#{$2}")
  super(object, lexical: @string)
end