Class: QueryService::WikidataDate
- Inherits:
-
Object
- Object
- QueryService::WikidataDate
- Includes:
- Comparable
- Defined in:
- lib/query_service.rb
Overview
a Wikidata date of a given precision
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.
57 58 59 60 |
# File 'lib/query_service.rb', line 57 def initialize(str, precision) @str = str @raw_precision = precision.to_s end |
Instance Method Details
#<=>(other) ⇒ Object
62 63 64 65 66 |
# File 'lib/query_service.rb', line 62 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
77 78 79 |
# File 'lib/query_service.rb', line 77 def empty? str.to_s.empty? end |
#month ⇒ Object
91 92 93 |
# File 'lib/query_service.rb', line 91 def month parts[1] end |
#precision ⇒ Object
81 82 83 84 85 |
# File 'lib/query_service.rb', line 81 def precision return '11' if raw_precision.empty? # default to YYYY-MM-DD raw_precision end |
#to_s ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/query_service.rb', line 68 def to_s return str if precision == '11' return str[0..6] if precision == '10' return str[0..3] if precision == '9' warn "Cannot handle precision #{precision} for #{str}" str end |
#year ⇒ Object
87 88 89 |
# File 'lib/query_service.rb', line 87 def year parts[0] end |