Class: Katalyst::Tables::Cells::NumberComponent
- Inherits:
-
Katalyst::Tables::CellComponent
- Object
- ViewComponent::Base
- Katalyst::Tables::CellComponent
- Katalyst::Tables::Cells::NumberComponent
- Includes:
- ActiveSupport::NumberHelper
- Defined in:
- app/components/katalyst/tables/cells/number_component.rb
Overview
Formats the value as a number
Adds a class to the cell to allow for custom styling
Instance Attribute Summary
Attributes inherited from Katalyst::Tables::CellComponent
#collection, #column, #record, #row
Instance Method Summary collapse
- #format(value) ⇒ Object
-
#initialize(format:, options:) ⇒ NumberComponent
constructor
A new instance of NumberComponent.
- #rendered_value ⇒ Object
Methods inherited from Katalyst::Tables::CellComponent
#call, #heading?, #inspect, #label, #to_s, #value, #with_content_wrapper
Constructor Details
#initialize(format:, options:) ⇒ NumberComponent
Returns a new instance of NumberComponent.
12 13 14 15 16 17 |
# File 'app/components/katalyst/tables/cells/number_component.rb', line 12 def initialize(format:, options:, **) super(**) @format = format @options = end |
Instance Method Details
#format(value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/components/katalyst/tables/cells/number_component.rb', line 19 def format(value) case @format when :phone number_to_phone(value, @options) when :currency number_to_currency(value, @options) when :percentage number_to_percentage(value, @options) when :delimited number_to_delimited(value, @options) when :rounded number_to_rounded(value, @options) when :human_size number_to_human_size(value, @options) when :human number_to_human(value, @options) else raise ArgumentError, "Unsupported format #{@format}" end end |
#rendered_value ⇒ Object
40 41 42 |
# File 'app/components/katalyst/tables/cells/number_component.rb', line 40 def rendered_value value.present? ? format(value) : "" end |