Sha256: 1f1e01ff4c87de5f46260729d54236bd3d7c52ee057b4d6438e1f94f2be28b1f

Contents?: true

Size: 976 Bytes

Versions: 5

Compression:

Stored size: 976 Bytes

Contents

# frozen_string_literal: true

require_relative 'version_helpers'

module PaperTrailScrapbook
  # Class Chapter provides single version history analysis
  #
  # @author Timothy Chambers <tim@hint.io>
  #
  class Chapter
    include Concord.new(:version)
    include Adamantium::Flat
    include PaperTrailScrapbook::VersionHelpers

    # Single version historical analysis
    #
    # @return [String] Human readable description of changes
    #
    def story
      updates = changes
      return unless tell_story?(updates)

      [preface, (updates unless destroy?)].compact.join("\n")
    end

    private

    def preface
      "On #{whenn}, #{who} #{kind} #{what}".squeeze(' ')
    end

    def what
      if destroy?
        "#{model}#{item_id}"
      else
        "the following #{model}#{item_id} info:"
      end
    end

    def item_id; end

    def tell_story?(updates)
      create? || destroy? || updates.present? || !config.filter_non_changes
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
paper_trail_scrapbook-0.2.0 lib/paper_trail_scrapbook/chapter.rb
paper_trail_scrapbook-0.1.21 lib/paper_trail_scrapbook/chapter.rb
paper_trail_scrapbook-0.1.20 lib/paper_trail_scrapbook/chapter.rb
paper_trail_scrapbook-0.1.19 lib/paper_trail_scrapbook/chapter.rb
paper_trail_scrapbook-0.1.18 lib/paper_trail_scrapbook/chapter.rb