Class: OpenHAB::CoreExt::Java::Duration
- Inherits:
-
Object
- Object
- OpenHAB::CoreExt::Java::Duration
- Includes:
- Between, TemporalAmount
- Defined in:
- lib/openhab/core_ext/java/duration.rb
Overview
Extensions to Java Duration
Instance Method Summary collapse
- #<=>(other) ⇒ Integer?
-
#coerce(other) ⇒ Array?
Converts
other
to Duration, if possible. -
#positive? ⇒ true, false
Returns true if the duration is greater than zero.
-
#to_f ⇒ Float
Convert to number of seconds.
-
#to_i ⇒ Integer
Convert to integer number of seconds.
-
#zero? ⇒ true, false
Returns true if the duration is zero length.
Methods included from TemporalAmount
#-@, #ago, #from_now, #inspect
Methods included from Between
Instance Method Details
#<=>(other) ⇒ Integer?
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.
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.
34 35 36 |
# File 'lib/openhab/core_ext/java/duration.rb', line 34 def positive? self > 0 # rubocop:disable Style/NumericPredicate end |
#to_f ⇒ Float
Convert to number of seconds
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 |
#to_i ⇒ Integer
Convert to integer number of seconds
18 |
# File 'lib/openhab/core_ext/java/duration.rb', line 18 alias_method :to_i, :seconds |
#zero? ⇒ true, false
Returns true if the duration is zero length.
|
# File 'lib/openhab/core_ext/java/duration.rb', line 20
|