Sha256: 21c59b834f60660f9f62635eccd812866b658d9ad76245b90ef2e6c4f7a70ba6

Contents?: true

Size: 843 Bytes

Versions: 8

Compression:

Stored size: 843 Bytes

Contents

# frozen_string_literal: true

class Code
  class Object
    class Duration < Object
      attr_reader :raw

      def initialize(duration)
        duration = duration.raw if duration.is_a?(Duration)
        @raw = duration
      end

      def self.name
        "Duration"
      end

      def call(**args)
        operator = args.fetch(:operator, nil)

        case operator.to_s
        when "ago"
          sig(args)
          code_ago
        when "from_now"
          sig(args)
          code_from_now
        else
          super
        end
      end

      def code_ago
        Time.new(raw.ago)
      end

      def code_from_now
        Time.new(raw.from_now)
      end

      def inspect
        to_s
      end

      def to_s
        raw.to_s
      end

      def as_json(...)
        raw.as_json(...)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
code-ruby-0.11.0 lib/code/object/duration.rb
code-ruby-0.10.4 lib/code/object/duration.rb
code-ruby-0.10.3 lib/code/object/duration.rb
code-ruby-0.10.2 lib/code/object/duration.rb
code-ruby-0.10.1 lib/code/object/duration.rb
code-ruby-0.10.0 lib/code/object/duration.rb
code-ruby-0.9.3 lib/code/object/duration.rb
code-ruby-0.9.2 lib/code/object/duration.rb