Class: OpenHAB::Core::Types::TimeSeries
- Inherits:
-
Object
- Object
- OpenHAB::Core::Types::TimeSeries
- Includes:
- LazyArray
- 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
-
#<<(entry) ⇒ self
Appends an entry to self, returns self.
-
#add(timestamp, 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.
-
#to_a ⇒ Array
Explicit conversion to Array.
Methods included from LazyArray
#each, #method_missing, #to_ary
Methods included from Enumerable
#all_groups, #all_members, #command, #command!, #decrease, #down, #equipments, #fast_forward, #groups, #increase, #locations, #member_of, #members, #move, #next, #not_member_of, #not_tagged, #off, #on, #pause, #play, #points, #previous, #refresh, #rewind, #stop, #tagged, #toggle, #up, #update, #update!
Constructor Details
#initialize(policy = :replace) ⇒ TimeSeries
Create a new instance of TimeSeries
59 60 61 62 |
# File 'lib/openhab/core/types/time_series.rb', line 59 def initialize(policy = :replace) policy = Policy.value_of(policy.to_s.upcase) if policy.is_a?(Symbol) super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OpenHAB::Core::LazyArray
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 41
|
#end ⇒ Instant (readonly)
Returns the timestamp of the last element in this series.
|
# File 'lib/openhab/core/types/time_series.rb', line 45
|
#policy ⇒ org.openhab.core.types.TimeSeries.Policy (readonly)
Returns the persistence policy of this series.
|
# File 'lib/openhab/core/types/time_series.rb', line 36
|
#size ⇒ Integer (readonly)
Returns the number of elements in this series.
|
# File 'lib/openhab/core/types/time_series.rb', line 49
|
Instance Method Details
#<<(entry) ⇒ self
Appends an entry to self, returns self
135 136 137 138 139 140 141 142 |
# File 'lib/openhab/core/types/time_series.rb', line 135 def <<(entry) raise ArgumentError, "entry must be an Array, but was #{entry.class}" unless entry.respond_to?(:to_ary) entry = entry.to_ary raise ArgumentError, "entry must be an Array of size 2, but was #{entry.size}" unless entry.size == 2 add(entry[0], entry[1]) end |
#add(timestamp, 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.
118 119 120 121 122 123 |
# File 'lib/openhab/core/types/time_series.rb', line 118 def add(timestamp, state) timestamp = to_instant(timestamp) state = format_state(state) add_instant(timestamp, state) self end |
#add? ⇒ true, false
Returns true if the series' policy is ADD
.
66 67 68 |
# File 'lib/openhab/core/types/time_series.rb', line 66 def add? policy == Policy::ADD end |
#replace? ⇒ true, false
Returns true if the series' policy is REPLACE
.
72 73 74 |
# File 'lib/openhab/core/types/time_series.rb', line 72 def replace? policy == Policy::REPLACE end |
#states ⇒ Array<org.openhab.core.types.TimeSeries.Entry>
Returns the content of this series.
96 97 98 |
# File 'lib/openhab/core/types/time_series.rb', line 96 def states to_a end |
#to_a ⇒ Array
Explicit conversion to Array
88 89 90 |
# File 'lib/openhab/core/types/time_series.rb', line 88 def to_a get_states.to_array.to_a.freeze end |