Class: QueryService::WikidataDate
- Inherits:
-
Object
- Object
- QueryService::WikidataDate
- Includes:
- Comparable
- Defined in:
- lib/query_service.rb
Overview
a Wikidata date of a given precision
Constant Summary collapse
- DATELEN =
{ '11' => 10, '10' => 7, '9' => 4, '8' => 4, '7' => 2 }.freeze
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(str, precision) ⇒ WikidataDate
constructor
A new instance of WikidataDate.
- #month ⇒ Object
- #precision ⇒ Object
- #to_s ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(str, precision) ⇒ WikidataDate
Returns a new instance of WikidataDate.
75 76 77 78 |
# File 'lib/query_service.rb', line 75 def initialize(str, precision) @str = str @raw_precision = precision.to_s end |
Instance Method Details
#<=>(other) ⇒ Object
80 81 82 83 84 |
# 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? ⇒ Boolean
90 91 92 |
# File 'lib/query_service.rb', line 90 def empty? str.to_s.empty? end |
#month ⇒ Object
104 105 106 |
# File 'lib/query_service.rb', line 104 def month parts[1] end |
#precision ⇒ Object
94 95 96 97 98 |
# 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 ⇒ Object
86 87 88 |
# File 'lib/query_service.rb', line 86 def to_s precisioned_string.delete_prefix('0') end |
#year ⇒ Object
100 101 102 |
# File 'lib/query_service.rb', line 100 def year parts[0] end |