Class: Datagrid::Filters::DynamicFilter::FilterValue

Inherits:
Object
  • Object
show all
Defined in:
lib/datagrid/filters/dynamic_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grid_class, object = nil) ⇒ FilterValue

Returns a new instance of FilterValue.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/datagrid/filters/dynamic_filter.rb', line 106

def initialize(grid_class, object = nil)
  super()

  case object
  when Hash
    object = object.symbolize_keys
    self.field = object[:field]
    self.operation = object[:operation]
    self.value = object[:value]
  when Array
    self.field = object[0]
    self.operation = object[1]
    self.value = object[2]
  else
    raise ArgumentError, object.inspect
  end
  return unless grid_class

  type = grid_class.driver.normalized_column_type(
    grid_class.scope, field,
  )
  self.value = type_cast(type, value)
end

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



104
105
106
# File 'lib/datagrid/filters/dynamic_filter.rb', line 104

def field
  @field
end

#operationObject

Returns the value of attribute operation.



104
105
106
# File 'lib/datagrid/filters/dynamic_filter.rb', line 104

def operation
  @operation
end

#valueObject

Returns the value of attribute value.



104
105
106
# File 'lib/datagrid/filters/dynamic_filter.rb', line 104

def value
  @value
end

Instance Method Details

#inspectObject



130
131
132
# File 'lib/datagrid/filters/dynamic_filter.rb', line 130

def inspect
  { field: field, operation: operation, value: value }
end

#to_aObject



138
139
140
# File 'lib/datagrid/filters/dynamic_filter.rb', line 138

def to_a
  [field, operation, value]
end

#to_aryObject



134
135
136
# File 'lib/datagrid/filters/dynamic_filter.rb', line 134

def to_ary
  to_a
end

#to_hObject



142
143
144
# File 'lib/datagrid/filters/dynamic_filter.rb', line 142

def to_h
  { field: field, operation: operation, value: value }
end