class TimeObj

Attributes

data[R]
end_method[R]
start_method[R]

Public Class Methods

new(data, start_method=:start, end_method=:end) click to toggle source
# File lib/TimeObj.rb, line 13
def initialize(data, start_method=:start, end_method=:end)
        if data.respond_to? :each
                @data = data
        else
                @data = [data]
        end
        if @data.class == Range || @data.class == Array
                start_method = :first
                end_method = :last
        end
        @start_method = start_method
        @end_method = end_method
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/TimeObj.rb, line 27
def <=>(other)
        @data <=> other.data
end
duration() click to toggle source
# File lib/TimeObj.rb, line 48
def duration
        self.end - start
end
end() click to toggle source
# File lib/TimeObj.rb, line 35
def end
        @data[@end_method]
end
merge(params) click to toggle source
# File lib/TimeObj.rb, line 39
def merge(params)
        if @data.respond_to? :attributes
                return @data.class.new(@data.attributes.merge(params))
        elsif @data.respond_to? :merge
                return @data.merge(params)
        end
        raise ArgumentError.new('Objects that are represented as times must respond to :attributes or :merge.')
end
start() click to toggle source
# File lib/TimeObj.rb, line 31
def start
        @data[@start_method]
end