Class: FastVersioning::Timeline

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_versioning/timeline.rb

Overview

a timeline for a tracked property

Instance Method Summary collapse

Constructor Details

#initialize(fast_versions:, name:) ⇒ Timeline

Returns a new instance of Timeline.

Parameters:

  • name (String)

    tracked property name

  • fast_versions (ActiveRecord::Collection)

    FastVersion collection



7
8
9
10
# File 'lib/fast_versioning/timeline.rb', line 7

def initialize(fast_versions:, name:)
  self.fast_versions = fast_versions
  self.name = name
end

Instance Method Details

#to_hHash

Returns hash of duration => date ranges.

Examples:


FastVersioning::Timeline.new(fast_versions: model.fast_versions, name: 'status').to_h

{
  Thu, 01 Apr 2021 14:08:48 EDT -04:00..Mon, 05 Apr 2021 21:53:48 EDT -04:00 => 'active',
  Mon, 05 Apr 2021 21:53:48 EDT -04:00..Mon, 05 Apr 2021 22:02:44 EDT -04:00 => 'inactive'
}

Returns:

  • (Hash)

    hash of duration => date ranges



23
24
25
26
27
# File 'lib/fast_versioning/timeline.rb', line 23

def to_h
  durations_array.map do |duration|
    [duration.date_range, duration.value]
  end.to_h
end