Class: OpenHAB::CoreExt::Java::Duration

Inherits:
Object
  • Object
show all
Includes:
Between, TemporalAmount
Defined in:
lib/openhab/core_ext/java/duration.rb

Overview

Extensions to Java Duration

Instance Method Summary collapse

Methods included from TemporalAmount

#-@, #ago, #from_now, #inspect

Methods included from Between

#between?

Instance Method Details

#<=>(other) ⇒ Integer?

Returns:



51
52
53
54
55
56
57
# File 'lib/openhab/core_ext/java/duration.rb', line 51

def <=>(other)
  return to_f <=> other if other.is_a?(Numeric)

  super
rescue TypeError
  nil
end

#coerce(other) ⇒ Array?

Converts ‘other` to OpenHAB::CoreExt::Java::Duration, if possible.

Parameters:

Returns:



65
66
67
68
69
# File 'lib/openhab/core_ext/java/duration.rb', line 65

def coerce(other)
  return [other.seconds, self] if other.is_a?(Numeric)

  [other.to_i.seconds, self] if other.is_a?(Period)
end

#positive?true, false

Returns true if the duration is greater than zero.

Returns:

  • (true, false)

    Returns true if the duration is greater than zero.



34
35
36
# File 'lib/openhab/core_ext/java/duration.rb', line 34

def positive?
  self > 0 # rubocop:disable Style/NumericPredicate
end

#to_fFloat

Convert to number of seconds

Returns:



44
45
46
# File 'lib/openhab/core_ext/java/duration.rb', line 44

def to_f
  to_i + (nano / 1_000_000_000.0)
end

#zero?true, false

Returns true if the duration is zero length.

Returns:

  • (true, false)

    Returns true if the duration is zero length.



# File 'lib/openhab/core_ext/java/duration.rb', line 20