Class: Jquard::Tables::Columns::TextColumn

Inherits:
Column
  • Object
show all
Defined in:
lib/jquard/tables/columns/text_column.rb

Instance Attribute Summary

Attributes inherited from Column

#name

Instance Method Summary collapse

Methods inherited from Column

#initialize, #label, make, #searchable, #searchable?, #sortable, #sortable?, #state_for

Methods included from ComponentDispatch

#component_class

Constructor Details

This class inherits a constructor from Jquard::Tables::Columns::Column

Instance Method Details

#badge(value = true) ⇒ Object



14
15
16
17
# File 'lib/jquard/tables/columns/text_column.rb', line 14

def badge(value = true)
  @badge = value
  self
end

#badge?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/jquard/tables/columns/text_column.rb', line 19

def badge?
  !!@badge
end

#color(map) ⇒ Object



23
24
25
26
# File 'lib/jquard/tables/columns/text_column.rb', line 23

def color(map)
  @color_map = map.transform_keys(&:to_sym)
  self
end

#color_for(state) ⇒ Object



28
29
30
# File 'lib/jquard/tables/columns/text_column.rb', line 28

def color_for(state)
  (@color_map || {}).fetch(state.to_s.to_sym, :gray)
end

#date_time(pattern = "%b %-d, %Y %H:%M") ⇒ Object



10
11
12
# File 'lib/jquard/tables/columns/text_column.rb', line 10

def date_time(pattern = "%b %-d, %Y %H:%M")
  format { |state| state.strftime(pattern) }
end

#display_value(record) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/jquard/tables/columns/text_column.rb', line 37

def display_value(record)
  state = state_for(record)
  return "" if state.nil?

  value = @formatter ? @formatter.call(state) : state
  value = value.to_s
  @limit ? value.truncate(@limit) : value
end

#format(&block) ⇒ Object



5
6
7
8
# File 'lib/jquard/tables/columns/text_column.rb', line 5

def format(&block)
  @formatter = block
  self
end

#limit(count) ⇒ Object



32
33
34
35
# File 'lib/jquard/tables/columns/text_column.rb', line 32

def limit(count)
  @limit = count
  self
end