Module: Trax::Model::ExtensionsFor::StructFields::Numeric::ClassMethods

Defined in:
lib/trax/model/extensions_for/struct_fields/numeric.rb

Instance Method Summary collapse

Instance Method Details

#between(lower_value, upper_value) ⇒ Object



10
11
12
# File 'lib/trax/model/extensions_for/struct_fields/numeric.rb', line 10

def between(lower_value, upper_value)
  gt(lower_value).merge(lt(upper_value))
end

#eq(*_scope_values) ⇒ Object



18
19
20
21
22
# File 'lib/trax/model/extensions_for/struct_fields/numeric.rb', line 18

def eq(*_scope_values)
  _scope_values.flat_compact_uniq!
  cast_type = type
  model_class.where("(#{parent_definition.field_name} ->> '#{field_name}')::#{cast_type} IN(?)", _scope_values)
end

#gt(value) ⇒ Object



24
25
26
27
28
# File 'lib/trax/model/extensions_for/struct_fields/numeric.rb', line 24

def gt(value)
  cast_type = type
  operator = '>'
  model_class.where("(#{parent_definition.field_name} ->> '#{field_name}')::#{cast_type} #{operator} ?", value)
end

#gte(value) ⇒ Object



30
31
32
33
34
# File 'lib/trax/model/extensions_for/struct_fields/numeric.rb', line 30

def gte(value)
  cast_type = type
  operator = '>='
  model_class.where("(#{parent_definition.field_name} ->> '#{field_name}')::#{cast_type} #{operator} ?", value)
end

#in_range(lower_value, upper_value) ⇒ Object



14
15
16
# File 'lib/trax/model/extensions_for/struct_fields/numeric.rb', line 14

def in_range(lower_value, upper_value)
  gte(lower_value).merge(lte(upper_value))
end

#lt(value) ⇒ Object



36
37
38
39
40
# File 'lib/trax/model/extensions_for/struct_fields/numeric.rb', line 36

def lt(value)
  cast_type = type
  operator = '<'
  model_class.where("(#{parent_definition.field_name} ->> '#{field_name}')::#{cast_type} #{operator} ?", value)
end

#lte(value) ⇒ Object



42
43
44
45
46
# File 'lib/trax/model/extensions_for/struct_fields/numeric.rb', line 42

def lte(value)
  cast_type = type
  operator = '<='
  model_class.where("(#{parent_definition.field_name} ->> '#{field_name}')::#{cast_type} #{operator} ?", value)
end