Sha256: 46516f3d23313459d940acbeb49f8cea6bcb78caadc31a096b7afd3c3e8323c3
Contents?: true
Size: 1.26 KB
Versions: 20
Compression:
Stored size: 1.26 KB
Contents
# frozen_string_literal: true module Katalyst module Tables module Cells # Formats the value as a number # # Adds a class to the cell to allow for custom styling class NumberComponent < CellComponent include ActiveSupport::NumberHelper def initialize(format:, options:, **) super(**) @format = format @options = options end 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 def rendered_value value.present? ? format(value) : "" end private def default_html_attributes { class: "type-number" } end end end end end
Version data entries
20 entries across 20 versions & 1 rubygems