Class: Noventius::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/noventius/filter.rb

Constant Summary collapse

RESERVED_ARGS =
%i(icon priority)
DEFAULT_RESERVED_ARGS =
{ priority: 0 }
TYPES =
%i(check_box color date datetime email month number phone radio_button range search select
telephone text_area text url week)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, dirty_args = {}) ⇒ Filter

Returns a new instance of Filter.



12
13
14
15
16
17
18
19
# File 'lib/noventius/filter.rb', line 12

def initialize(name, type, dirty_args = {})
  fail ArgumentError, "FilterType: [#{type}] not yet implemented." unless TYPES.include?(type.to_sym)

  @name = name.to_sym
  @type = type.to_sym
  @args = clean_args(dirty_args)
  @options = DEFAULT_RESERVED_ARGS.merge(reserved_args(dirty_args))
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'lib/noventius/filter.rb', line 10

def args
  @args
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/noventius/filter.rb', line 10

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/noventius/filter.rb', line 10

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/noventius/filter.rb', line 10

def type
  @type
end

Instance Method Details

#deep_dupObject



30
31
32
# File 'lib/noventius/filter.rb', line 30

def deep_dup
  Marshal.load(Marshal.dump(self))
end

#to_jsObject



21
22
23
24
25
26
27
28
# File 'lib/noventius/filter.rb', line 21

def to_js
  {
    "#{name}" => {
      type: type,
      options: options
    }
  }
end