Class: IndexView::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/index_view/column.rb

Defined Under Namespace

Classes: InvalidKeyError

Constant Summary collapse

OPTION_KEYS =
[:link, :sortable, :title, :searchable]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column_name, options = { }, &link) ⇒ Column

Returns a new instance of Column.



7
8
9
10
11
# File 'lib/index_view/column.rb', line 7

def initialize(column_name, options={ }, &link)
  @column_name = column_name.to_sym

  check_and_assign_values_from_keys(options, link)
end

Instance Attribute Details

#column_nameObject (readonly)

Returns the value of attribute column_name.



13
14
15
# File 'lib/index_view/column.rb', line 13

def column_name
  @column_name
end

Returns the value of attribute link.



13
14
15
# File 'lib/index_view/column.rb', line 13

def link
  @link
end

Instance Method Details

#column_value(context, object) ⇒ Object



15
16
17
# File 'lib/index_view/column.rb', line 15

def column_value(context, object)
  context.instance_exec(object, &link)
end

#column_value?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/index_view/column.rb', line 19

def column_value?
  link ? true : false
end

#human_nameObject



27
28
29
# File 'lib/index_view/column.rb', line 27

def human_name
  column_name.to_s.humanize
end

#searchable?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/index_view/column.rb', line 35

def searchable?
  @searchable ? true : false
end

#sortable?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/index_view/column.rb', line 23

def sortable?
  @sortable ? true : false
end

#titleObject



31
32
33
# File 'lib/index_view/column.rb', line 31

def title
  @title ? @title : human_name
end