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.
59 60 61 62 |
# File 'lib/query_service.rb', line 59 def initialize(str, precision) @str = str @raw_precision = precision.to_s end |
Instance Method Details
#<=>(other) ⇒ Object
64 65 66 67 68 |
# File 'lib/query_service.rb', line 64 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
74 75 76 |
# File 'lib/query_service.rb', line 74 def empty? str.to_s.empty? end |
#month ⇒ Object
88 89 90 |
# File 'lib/query_service.rb', line 88 def month parts[1] end |
#precision ⇒ Object
78 79 80 81 82 |
# File 'lib/query_service.rb', line 78 def precision return '11' if raw_precision.empty? # default to YYYY-MM-DD raw_precision end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/query_service.rb', line 70 def to_s precisioned_string.delete_prefix('0') end |
#year ⇒ Object
84 85 86 |
# File 'lib/query_service.rb', line 84 def year parts[0] end |