Module: SearchSolrTools::Helpers::TranslateTemporalCoverage

Defined in:
lib/search_solr_tools/helpers/translate_temporal_coverage.rb

Overview

Methods to translate temporal coverage object to solr format values

Class Method Summary collapse

Class Method Details

.format_string(value) ⇒ Object



33
34
35
# File 'lib/search_solr_tools/helpers/translate_temporal_coverage.rb', line 33

def self.format_string(value)
  value.to_s.empty? ? nil : value.strftime('%Y-%m-%d')
end

.time_string(coverage, key) ⇒ Object



37
38
39
# File 'lib/search_solr_tools/helpers/translate_temporal_coverage.rb', line 37

def self.time_string(coverage, key)
  Time.parse(coverage[key]) unless coverage[key].to_s.empty?
end

.translate_coverages(temporal_coverages_json) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/search_solr_tools/helpers/translate_temporal_coverage.rb', line 11

def self.translate_coverages(temporal_coverages_json)
  temporal_coverages = temporal_coverages_json.to_a.map do |coverage|
    start_time = time_string(coverage, 'start')
    end_time = time_string(coverage, 'end')

    [
      SolrFormat.temporal_index_str(start: start_time.to_s, end: end_time.to_s),
      SolrFormat.temporal_display_str(start: format_string(start_time), end: format_string(end_time)),
      SolrFormat.get_temporal_duration(start_time, end_time)
    ]
  end.transpose

  temporal_index_str = temporal_coverages[0] || []
  temporal_display   = temporal_coverages[1] || []
  temporal_durations = temporal_coverages[2] || []

  max_temporal_duration = SolrFormat.reduce_temporal_duration(temporal_durations)
  facet = SolrFormat.get_temporal_duration_facet(max_temporal_duration)

  { 'temporal_coverages' => temporal_display, 'temporal_duration' => max_temporal_duration, 'temporal' => temporal_index_str, 'facet_temporal_duration' => facet }
end