Class: OpenHAB::Core::Types::TimeSeries
- Inherits:
-
Object
- Object
- OpenHAB::Core::Types::TimeSeries
- Defined in:
- lib/openhab/core/types/time_series.rb
Overview
TimeSeries is used to transport a set of states together with their timestamp.
The states are sorted chronologically. The entries can be accessed like an array.
Instance Attribute Summary collapse
-
#begin ⇒ Instant
readonly
Returns the timestamp of the first element in this series.
-
#end ⇒ Instant
readonly
Returns the timestamp of the last element in this series.
-
#policy ⇒ org.openhab.core.types.TimeSeries.Policy
readonly
Returns the persistence policy of this series.
-
#size ⇒ Integer
readonly
Returns the number of elements in this series.
Instance Method Summary collapse
-
#add(instant, state) ⇒ self
Adds a new element to this series.
-
#add? ⇒ true, false
Returns true if the series' policy is
ADD
. -
#initialize(policy = :replace) ⇒ TimeSeries
constructor
Create a new instance of TimeSeries.
-
#replace? ⇒ true, false
Returns true if the series' policy is
REPLACE
. -
#states ⇒ Array<org.openhab.core.types.TimeSeries.Entry>
Returns the content of this series.
Constructor Details
#initialize(policy = :replace) ⇒ TimeSeries
Create a new instance of TimeSeries
58 59 60 61 |
# File 'lib/openhab/core/types/time_series.rb', line 58 def initialize(policy = :replace) policy = Policy.value_of(policy.to_s.upcase) if policy.is_a?(Symbol) super end |
Instance Attribute Details
#begin ⇒ Instant (readonly)
Returns the timestamp of the first element in this series.
|
# File 'lib/openhab/core/types/time_series.rb', line 40
|
#end ⇒ Instant (readonly)
Returns the timestamp of the last element in this series.
|
# File 'lib/openhab/core/types/time_series.rb', line 44
|
#policy ⇒ org.openhab.core.types.TimeSeries.Policy (readonly)
Returns the persistence policy of this series.
|
# File 'lib/openhab/core/types/time_series.rb', line 35
|
#size ⇒ Integer (readonly)
Returns the number of elements in this series.
|
# File 'lib/openhab/core/types/time_series.rb', line 48
|
Instance Method Details
#add(instant, state) ⇒ self
This method returns self so it can be chained, unlike the Java version.
Adds a new element to this series.
Elements can be added in an arbitrary order and are sorted chronologically.
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/openhab/core/types/time_series.rb', line 110 def add(instant, state) instant = instant.to_zoned_date_time if instant.respond_to?(:to_zoned_date_time) instant = instant.to_instant if instant.respond_to?(:to_instant) state = case state when State then state when String then StringType.new(state) when Numeric then DecimalType.new(state) else raise ArgumentError, "state must be a State, String or Numeric, but was #{state.class}" end add_instant(instant, state) self end |
#add? ⇒ true, false
Returns true if the series' policy is ADD
.
65 66 67 |
# File 'lib/openhab/core/types/time_series.rb', line 65 def add? policy == Policy::ADD end |
#replace? ⇒ true, false
Returns true if the series' policy is REPLACE
.
71 72 73 |
# File 'lib/openhab/core/types/time_series.rb', line 71 def replace? policy == Policy::REPLACE end |
#states ⇒ Array<org.openhab.core.types.TimeSeries.Entry>
Returns the content of this series.
88 89 90 |
# File 'lib/openhab/core/types/time_series.rb', line 88 def states get_states.to_array.to_a.freeze end |