Class: Redis::TimeSeries::Filters

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/time_series/filters.rb

Defined Under Namespace

Classes: Absent, AnyValue, Equal, NoValues, NotEqual, Present

Constant Summary collapse

TYPES =
[Equal, NotEqual, Absent, Present, AnyValue, NoValues]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filters = nil) ⇒ Filters

Returns a new instance of Filters.



114
115
116
117
118
119
120
# File 'lib/redis/time_series/filters.rb', line 114

def initialize(filters = nil)
  @filters = case filters
             when String then parse_string(filters)
             when Hash then parse_hash(filters)
             else []
             end
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



112
113
114
# File 'lib/redis/time_series/filters.rb', line 112

def filters
  @filters
end

Instance Method Details

#to_aObject



130
131
132
# File 'lib/redis/time_series/filters.rb', line 130

def to_a
  filters.map(&:to_s)
end

#to_hObject



134
135
136
# File 'lib/redis/time_series/filters.rb', line 134

def to_h
  filters.reduce({}) { |h, filter| h.merge(filter.to_h) }
end

#to_sObject



138
139
140
# File 'lib/redis/time_series/filters.rb', line 138

def to_s
  to_a.join(' ')
end

#valid?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/redis/time_series/filters.rb', line 126

def valid?
  !!filters.find { |f| f.is_a?(Equal) || f.is_a?(AnyValue)}
end

#validate!Object



122
123
124
# File 'lib/redis/time_series/filters.rb', line 122

def validate!
  valid? || raise(FilterError, 'Filtering requires at least one equality comparison')
end