Class: Katalyst::Tables::Label

Inherits:
Object
  • Object
show all
Defined in:
app/components/katalyst/tables/label.rb

Instance Method Summary collapse

Constructor Details

#initialize(collection:, column:, label: nil) ⇒ Label

Returns a new instance of Label.



6
7
8
9
10
# File 'app/components/katalyst/tables/label.rb', line 6

def initialize(collection:, column:, label: nil)
  @collection = collection
  @column = column
  @label = label
end

Instance Method Details

#callObject Also known as: to_s



24
25
26
27
28
# File 'app/components/katalyst/tables/label.rb', line 24

def call
  ActionView::OutputBuffer.new.tap do |output|
    output << value.to_s
  end.to_s
end

#inspectObject



32
33
34
# File 'app/components/katalyst/tables/label.rb', line 32

def inspect
  "#<#{self.class.name} column: #{@column.inspect} value: #{value.inspect}>"
end

#valueObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/components/katalyst/tables/label.rb', line 12

def value
  return @value if defined?(@value)

  @value = if !@label.nil?
             @label
           elsif @collection.model.present?
             @collection.model.human_attribute_name(@column)
           else
             @column.to_s.humanize.capitalize
           end
end