Sha256: 32d78cda368ba80609594405fcc20be74ac8eacfa140438d935bd658379b689e

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

module SnapshotArchive
  module Formatters
    class List
      def self.call(metadata)
        new(metadata).call
      end

      attr_reader :metadata
      def initialize(metadata)
        @metadata = metadata
      end

      def call
        id = metadata.fetch("id")
        timestamp = Time.parse(metadata.fetch("timestamp")).strftime("%F %H:%M")
        message = metadata.fetch("message")

        short_message = message.split("\n").first
        Cfg.shell.puts([id, timestamp, short_message].join(" : "))
      end
    end

    class Show
      def self.call(metadata)
        new(metadata).call
      end

      attr_reader :metadata
      def initialize(metadata)
        @metadata = metadata
      end

      def call
        id = metadata.fetch("id")
        timestamp = Time.parse(metadata.fetch("timestamp")).strftime("%F %H:%M")
        message = metadata.fetch("message")
        dir = metadata.fetch("dir")

        Cfg.shell.puts(<<~TXT)
          id: #{id}
          time: #{timestamp}
          path: #{dir}
          ----------------------
          #{message}
        TXT
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
snapshot_archive-0.3.0 lib/snapshot_archive/formatters.rb
snapshot_archive-0.2.0 lib/snapshot_archive/formatters.rb
snapshot_archive-0.1.0 lib/snapshot_archive/formatters.rb