Class: Warped::Filter::Base::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/warped/api/filter/base/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter, relation, value) ⇒ Value

Returns a new instance of Value.

Parameters:



17
18
19
20
21
# File 'lib/warped/api/filter/base/value.rb', line 17

def initialize(filter, relation, value)
  @filter = filter
  @relation = relation
  @value = value
end

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter.



10
11
12
# File 'lib/warped/api/filter/base/value.rb', line 10

def filter
  @filter
end

Instance Method Details

#empty?Boolean

Returns Whether the filter is empty.

Returns:

  • (Boolean)

    Whether the filter is empty.



34
35
36
# File 'lib/warped/api/filter/base/value.rb', line 34

def empty?
  value.nil? && !%w[is_null is_not_null].include?(relation)
end

#relationString

Returns The validated filter relation.

Returns:

  • (String)

    The validated filter relation.



29
30
31
# File 'lib/warped/api/filter/base/value.rb', line 29

def relation
  filter.relation(@relation)
end

#to_hObject



38
39
40
41
42
43
44
# File 'lib/warped/api/filter/base/value.rb', line 38

def to_h
  {
    field: filter.name,
    relation:,
    value:
  }
end

#valueString Also known as: html_value

Returns The casted filter value.

Returns:

  • (String)

    The casted filter value.



24
25
26
# File 'lib/warped/api/filter/base/value.rb', line 24

def value
  filter.cast(@value)
end