Class: PaperTrail::Human::Core::Timeline

Inherits:
Object
  • Object
show all
Defined in:
lib/paper_trail/human/core/timeline.rb

Constant Summary collapse

GROUPINGS =
{
  day: '%Y-%m-%d',
  week: '%G-W%V',
  month: '%Y-%m',
  year: '%Y'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Timeline

Returns a new instance of Timeline.



14
15
16
17
# File 'lib/paper_trail/human/core/timeline.rb', line 14

def initialize(configuration)
  @configuration = configuration
  @batch_presenter = BatchPresenter.new(configuration)
end

Instance Method Details

#call(versions, group_by: :day, only: nil, except: nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/paper_trail/human/core/timeline.rb', line 19

def call(versions, group_by: :day, only: nil, except: nil)
  formatted = @batch_presenter.call(versions, only: only, except: except)
  format_str = GROUPINGS.fetch(group_by.to_sym) do
    raise Error, "Unknown group_by: #{group_by}. Available: #{GROUPINGS.keys.join(', ')}"
  end

  formatted.group_by { |r| r[:created_at].strftime(format_str) }
end