class ActiveSupport::Duration::Scalar
:nodoc:
def %(other)
def %(other) if Duration === other Duration.build(value % other.value) else calculate(:%, other) end end
def *(other)
def *(other) if Duration === other new_parts = other._parts.transform_values { |other_value| value * other_value } new_value = value * other.value Duration.new(new_value, new_parts, other.variable?) else calculate(:*, other) end end
def +(other)
def +(other) if Duration === other seconds = value + other._parts.fetch(:seconds, 0) new_parts = other._parts.merge(seconds: seconds) new_value = value + other.value Duration.new(new_value, new_parts, other.variable?) else calculate(:+, other) end end
def -(other)
def -(other) if Duration === other seconds = value - other._parts.fetch(:seconds, 0) new_parts = other._parts.transform_values(&:-@) new_parts = new_parts.merge(seconds: seconds) new_value = value - other.value Duration.new(new_value, new_parts, other.variable?) else calculate(:-, other) end end
def -@
def -@ Scalar.new(-value) end
def /(other)
def /(other) if Duration === other value / other.value else calculate(:/, other) end end
def <=>(other)
def <=>(other) if Scalar === other || Duration === other value <=> other.value elsif Numeric === other value <=> other else nil end end
def calculate(op, other)
def calculate(op, other) if Scalar === other Scalar.new(value.public_send(op, other.value)) elsif Numeric === other Scalar.new(value.public_send(op, other)) else raise_type_error(other) end end
def coerce(other)
def coerce(other) [Scalar.new(other), self] end
def initialize(value)
def initialize(value) @value = value end
def raise_type_error(other)
def raise_type_error(other) raise TypeError, "no implicit conversion of #{other.class} into #{self.class}" end
def variable? # :nodoc:
def variable? # :nodoc: false end