Class: Mensa::Filter

Inherits:
Object
  • Object
show all
Includes:
ConfigReaders
Defined in:
app/tables/mensa/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, column:, config:, table:) ⇒ Filter

Returns a new instance of Filter.



10
11
12
13
14
15
# File 'app/tables/mensa/filter.rb', line 10

def initialize(value, column:, config:, table:)
  @value = value
  @column = column
  @config = config
  @table = table
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



6
7
8
# File 'app/tables/mensa/filter.rb', line 6

def column
  @column
end

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'app/tables/mensa/filter.rb', line 6

def config
  @config
end

#tableObject (readonly)

Returns the value of attribute table.



6
7
8
# File 'app/tables/mensa/filter.rb', line 6

def table
  @table
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'app/tables/mensa/filter.rb', line 6

def value
  @value
end

Instance Method Details

#collectionObject



17
18
19
20
21
22
23
24
25
# File 'app/tables/mensa/filter.rb', line 17

def collection
  return unless config&.key?(:collection)

  if config[:collection].is_a? Proc
    table.original_view_context.instance_exec(&config[:collection])
  else
    config[:collection]
  end
end

#to_sObject



27
28
29
# File 'app/tables/mensa/filter.rb', line 27

def to_s
  "#{column.human_name}: #{value}"
end