Class: ActiveSupport::Duration::Scalar

Inherits:
Numeric show all
Defined in:
lib/active_support/duration.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Numeric

Numeric::EXABYTE, Numeric::GIGABYTE, Numeric::KILOBYTE, Numeric::MEGABYTE, Numeric::PETABYTE, Numeric::TERABYTE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Numeric

#as_json, #blank?, #bytes, #days, #exabytes, #fortnights, #gigabytes, #hours, #html_safe?, #in_milliseconds, #kilobytes, #megabytes, #minutes, #negative?, #petabytes, #positive?, #seconds, #terabytes, #weeks

Constructor Details

#initialize(value) ⇒ Scalar

Returns a new instance of Scalar.



17
18
19
# File 'lib/active_support/duration.rb', line 17

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



14
15
16
# File 'lib/active_support/duration.rb', line 14

def value
  @value
end

Instance Method Details

#*(other) ⇒ Object



47
48
49
# File 'lib/active_support/duration.rb', line 47

def *(other)
  calculate(:*, other)
end

#+(other) ⇒ Object



39
40
41
# File 'lib/active_support/duration.rb', line 39

def +(other)
  calculate(:+, other)
end

#-(other) ⇒ Object



43
44
45
# File 'lib/active_support/duration.rb', line 43

def -(other)
  calculate(:-, other)
end

#-@Object



25
26
27
# File 'lib/active_support/duration.rb', line 25

def -@
  Scalar.new(-value)
end

#/(other) ⇒ Object



51
52
53
# File 'lib/active_support/duration.rb', line 51

def /(other)
  calculate(:/, other)
end

#<=>(other) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/active_support/duration.rb', line 29

def <=>(other)
  if Scalar === other || Duration === other
    value <=> other.value
  elsif Numeric === other
    value <=> other
  else
    nil
  end
end

#coerce(other) ⇒ Object



21
22
23
# File 'lib/active_support/duration.rb', line 21

def coerce(other)
  [Scalar.new(other), self]
end