Class: FilterParam::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/filter_param/field.rb

Constant Summary collapse

TYPES =
%i[boolean string integer decimal date datetime].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, options = {}) ⇒ Field

Returns a new instance of Field.



7
8
9
10
11
12
# File 'lib/filter_param/field.rb', line 7

def initialize(name, type, options = {})
  @name = name
  @type = field_type(type)
  @rename = field_rename(options[:rename])
  @value_transformer = options[:value]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/filter_param/field.rb', line 5

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/filter_param/field.rb', line 5

def type
  @type
end

Instance Method Details

#actual_nameObject



20
21
22
# File 'lib/filter_param/field.rb', line 20

def actual_name
  rename.presence || name
end

#allow_operator?(operator) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/filter_param/field.rb', line 24

def allow_operator?(operator)
  true
end

#transform_value(value) ⇒ Object



14
15
16
17
18
# File 'lib/filter_param/field.rb', line 14

def transform_value(value)
  return value if value_transformer.blank?

  value_transformer.call(value)
end