class QueryService::WikidataDate
a Wikidata date of a given precision
Constants
- DATELEN
Attributes
raw_precision[R]
str[R]
Public Class Methods
new(str, precision)
click to toggle source
# File lib/query_service.rb, line 75 def initialize(str, precision) @str = str @raw_precision = precision.to_s end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/query_service.rb, line 80 def <=>(other) return to_s <=> other.to_s if precision == other.precision return year <=> other.year if year != other.year return month <=> other.month if month && other.month end
empty?()
click to toggle source
# File lib/query_service.rb, line 90 def empty? str.to_s.empty? end
month()
click to toggle source
# File lib/query_service.rb, line 104 def month parts[1] end
precision()
click to toggle source
# File lib/query_service.rb, line 94 def precision return '11' if raw_precision.empty? # default to YYYY-MM-DD raw_precision end
to_s()
click to toggle source
# File lib/query_service.rb, line 86 def to_s precisioned_string.delete_prefix('0') end
year()
click to toggle source
# File lib/query_service.rb, line 100 def year parts[0] end
Private Instance Methods
parts()
click to toggle source
# File lib/query_service.rb, line 112 def parts to_s.split('-') end
precisioned_string()
click to toggle source
# File lib/query_service.rb, line 123 def precisioned_string return "#{truncated_string}. century" if precision == '7' return "#{truncated_string}s" if precision == '8' truncated_string end
truncated_string()
click to toggle source
# File lib/query_service.rb, line 116 def truncated_string return str[0...DATELEN[precision]] if DATELEN.key?(precision) warn "Cannot handle precision #{precision} for #{str}" str end