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
Ruby's Integer and Float classes are extended to allow convenient creation of Duration instances.
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?
59 60 61 62 63 64 65 |
# File 'lib/openhab/core_ext/java/duration.rb', line 59 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.
73 74 75 76 77 |
# File 'lib/openhab/core_ext/java/duration.rb', line 73 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.
42 43 44 |
# File 'lib/openhab/core_ext/java/duration.rb', line 42 def positive? self > 0 # rubocop:disable Style/NumericPredicate end |
#to_f ⇒ Float
Convert to number of seconds
52 53 54 |
# File 'lib/openhab/core_ext/java/duration.rb', line 52 def to_f to_i + (nano / 1_000_000_000.0) end |
#to_i ⇒ Integer
Convert to integer number of seconds
26 |
# File 'lib/openhab/core_ext/java/duration.rb', line 26 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 28
|