Class: Emendate::ParsedDate

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(date:, orig:, qualifiers: []) ⇒ ParsedDate

Returns a new instance of ParsedDate.

Parameters:

  • date (Emendate::DateTypes::DateType)
  • orig (String)
  • qualifiers (Array<Emendate::Qualifier>) (defaults to: [])

Raises:



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_endObject (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_fullObject (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_startObject (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_fullObject (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_typeString (readonly)

Returns:

  • (String)


27
28
29
# File 'lib/emendate/parsed_date.rb', line 27

def date_type
  @date_type
end

#inclusive_rangeBoolean (readonly)

Returns:

  • (Boolean)


23
24
25
# File 'lib/emendate/parsed_date.rb', line 23

def inclusive_range
  @inclusive_range
end

#original_stringString (readonly)

Returns:

  • (String)


17
18
19
# File 'lib/emendate/parsed_date.rb', line 17

def original_string
  @original_string
end

#qualifiersArray<Emendate::Qualifier> (readonly)

Returns:

  • (Array<Emendate::Qualifier>)


25
26
27
# File 'lib/emendate/parsed_date.rb', line 25

def qualifiers
  @qualifiers
end

#sourceEmendate::DateTypes::DateType (readonly)

Returns:

  • (Emendate::DateTypes::DateType)


29
30
31
# File 'lib/emendate/parsed_date.rb', line 29

def source
  @source
end

Instance Method Details

#set_typeObject



70
71
72
73
74
# File 'lib/emendate/parsed_date.rb', line 70

def set_type
  source.set_type
rescue
  nil
end

#to_hObject



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_jsonObject



65
66
67
# File 'lib/emendate/parsed_date.rb', line 65

def to_json
  to_h.to_json
end