Class: Mensa::Row

Inherits:
Object
  • Object
show all
Defined in:
app/tables/mensa/row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, record) ⇒ Row

Returns a new instance of Row.



7
8
9
10
# File 'app/tables/mensa/row.rb', line 7

def initialize(table, record)
  @table = table
  @record = record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



5
6
7
# File 'app/tables/mensa/row.rb', line 5

def record
  @record
end

#tableObject (readonly)

Returns the value of attribute table.



5
6
7
# File 'app/tables/mensa/row.rb', line 5

def table
  @table
end

#view_contextObject (readonly)

Returns the value of attribute view_context.



5
6
7
# File 'app/tables/mensa/row.rb', line 5

def view_context
  @view_context
end

Instance Method Details



32
33
34
# File 'app/tables/mensa/row.rb', line 32

def link
  table.original_view_context.instance_exec(record, &table.link) if table.link
end


26
27
28
29
30
# File 'app/tables/mensa/row.rb', line 26

def link_attributes
  return {} unless link

  { href: link, data: { controller: "satis-link",  action: "click->satis-link#follow tap->satis-link#follow" } }
end

#value(column) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/tables/mensa/row.rb', line 12

def value(column)
  if column.attribute && record.respond_to?(column.attribute)
    record.public_send(column.attribute)
  elsif column.method && record.respond_to?(column.method)
    record.public_send(column.method)
  elsif record.respond_to?(column.name)
    record.public_send(column.name)
  elsif record.respond_to?(:[])
    record[column.name]
  else
    "-"
  end
end