Sha256: b23102aad04c0686eb65702e83c3bdd6a749a044f00f3fcff3569ffbba934698

Contents?: true

Size: 815 Bytes

Versions: 10

Compression:

Stored size: 815 Bytes

Contents

module Chronic
  # A Span represents a range of time. Since this class extends
  # Range, you can use #begin and #end to get the beginning and
  # ending times of the span (they will be of class Time)
  class Span < Range
    # Returns the width of this span in seconds
    def width
      (self.end - self.begin).to_i
    end

    # Add a number of seconds to this span, returning the
    # resulting Span
    def +(seconds)
      Span.new(self.begin + seconds, self.end + seconds)
    end

    # Subtract a number of seconds to this span, returning the
    # resulting Span
    def -(seconds)
      self + -seconds
    end

    # Prints this span in a nice fashion
    def to_s
      '(' << self.begin.to_s << '..' << self.end.to_s << ')'
    end

    alias :cover? :include? if RUBY_VERSION =~ /^1.8/

  end
end

Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
gitlab-chronic-0.10.6 lib/chronic/span.rb
gitlab-chronic-0.10.5 lib/chronic/span.rb
gitlab-chronic-0.10.4 lib/chronic/span.rb
gitlab-chronic-0.10.3 lib/chronic/span.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/chronic-0.10.2/lib/chronic/span.rb
chronic-mmlac-0.10.2.1 lib/chronic/span.rb
chronic-0.10.2 lib/chronic/span.rb
chronic-0.10.1 lib/chronic/span.rb
chronic-0.10.0 lib/chronic/span.rb
chronic-0.9.1 lib/chronic/span.rb