Sha256: e18c7cd9779b131704ef2ad7d922dbd6fb801120567ac7bfd0fc5fd5f7de779c

Contents?: true

Size: 993 Bytes

Versions: 4

Compression:

Stored size: 993 Bytes

Contents

# frozen_string_literal: true

module PaperTrailScrapbook
  # Class LifeHistory provides Full multi version history
  #
  # @author Timothy Chambers <tim@possibilogy.com>
  #
  class LifeHistory
    def initialize(object)
      @object   = object
      @versions = object.versions
      if object.respond_to?(:trailed_related_content)
        object.trailed_related_content.compact.each do |trc|
          @versions |= trc.versions
        end
      end

      @versions = @versions.sort_by(&:created_at)
    end

    # Retries textual historical analysis of versions
    #
    # @return [String] analyzed versions
    #
    def story
      versions.map do |v|
        if primary?(v)
          Chapter
        else
          SecondaryChapter
        end.new(v).story
      end.compact.join("\n\n")
    end

    private

    def primary?(version)
      version.item_type.eql?(object.class.name) &&
        version.item_id.equal?(object.id)
    end

    attr_reader :object, :versions
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
paper_trail_scrapbook-0.1.13 lib/paper_trail_scrapbook/life_history.rb
paper_trail_scrapbook-0.1.12 lib/paper_trail_scrapbook/life_history.rb
paper_trail_scrapbook-0.1.11 lib/paper_trail_scrapbook/life_history.rb
paper_trail_scrapbook-0.1.10 lib/paper_trail_scrapbook/life_history.rb