Class: Emendate::ParsedDate
- Inherits:
-
Object
- Object
- Emendate::ParsedDate
- Extended by:
- Forwardable
- Includes:
- Qualifiable
- Defined in:
- lib/emendate/parsed_date.rb
Overview
TODO:
Implement index dates (see timetwister)
Wrapper around a DateType segment, used as part of Result
Instance Attribute Summary collapse
-
#date_end ⇒ Object
readonly
Returns the value of attribute date_end.
-
#date_end_full ⇒ Object
readonly
Returns the value of attribute date_end_full.
-
#date_start ⇒ Object
readonly
Returns the value of attribute date_start.
-
#date_start_full ⇒ Object
readonly
Returns the value of attribute date_start_full.
- #date_type ⇒ String readonly
- #inclusive_range ⇒ Boolean readonly
- #original_string ⇒ String readonly
- #qualifiers ⇒ Array<Emendate::Qualifier> readonly
- #source ⇒ Emendate::DateTypes::DateType readonly
Instance Method Summary collapse
-
#initialize(date:, orig:, qualifiers: []) ⇒ ParsedDate
constructor
A new instance of ParsedDate.
- #set_type ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(date:, orig:, qualifiers: []) ⇒ ParsedDate
Returns a new instance of ParsedDate.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/emendate/parsed_date.rb', line 40 def initialize(date:, orig:, qualifiers: []) raise(NonDateTypeError) unless date.date_type? @original_string = get_original_string(date, orig) @date_start = nil @date_end = nil @date_start_full = date.earliest&.iso8601 @date_end_full = date.latest&.iso8601 @inclusive_range = date.range? @qualifiers = (qualifiers + date.qualifiers).flatten.uniq @date_type = date.class.name.split("::")[-1] @source = date end |
Instance Attribute Details
#date_end ⇒ Object (readonly)
Returns the value of attribute date_end.
19 20 21 |
# File 'lib/emendate/parsed_date.rb', line 19 def date_end @date_end end |
#date_end_full ⇒ Object (readonly)
Returns the value of attribute date_end_full.
21 22 23 |
# File 'lib/emendate/parsed_date.rb', line 21 def date_end_full @date_end_full end |
#date_start ⇒ Object (readonly)
Returns the value of attribute date_start.
18 19 20 |
# File 'lib/emendate/parsed_date.rb', line 18 def date_start @date_start end |
#date_start_full ⇒ Object (readonly)
Returns the value of attribute date_start_full.
20 21 22 |
# File 'lib/emendate/parsed_date.rb', line 20 def date_start_full @date_start_full end |
#date_type ⇒ String (readonly)
27 28 29 |
# File 'lib/emendate/parsed_date.rb', line 27 def date_type @date_type end |
#inclusive_range ⇒ Boolean (readonly)
23 24 25 |
# File 'lib/emendate/parsed_date.rb', line 23 def inclusive_range @inclusive_range end |
#original_string ⇒ String (readonly)
17 18 19 |
# File 'lib/emendate/parsed_date.rb', line 17 def original_string @original_string end |
#qualifiers ⇒ Array<Emendate::Qualifier> (readonly)
25 26 27 |
# File 'lib/emendate/parsed_date.rb', line 25 def qualifiers @qualifiers end |
#source ⇒ Emendate::DateTypes::DateType (readonly)
29 30 31 |
# File 'lib/emendate/parsed_date.rb', line 29 def source @source end |
Instance Method Details
#set_type ⇒ Object
70 71 72 73 74 |
# File 'lib/emendate/parsed_date.rb', line 70 def set_type source.set_type rescue nil end |
#to_h ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/emendate/parsed_date.rb', line 54 def to_h hashable_variables.map do |var| varsym = var.to_s.sub("@", "").to_sym [varsym, instance_variable_get(var)] end.to_h .merge({ range_switch: range_switch, era: era }) end |
#to_json ⇒ Object
65 66 67 |
# File 'lib/emendate/parsed_date.rb', line 65 def to_json to_h.to_json end |