Class: IronAdmin::Dashboards::MetricCardComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- IronAdmin::Dashboards::MetricCardComponent
- Defined in:
- app/components/iron_admin/dashboards/metric_card_component.rb
Overview
Renders a metric card with name and formatted value.
Instance Attribute Summary collapse
-
#icon ⇒ String?
readonly
private
Heroicon name.
Instance Method Summary collapse
-
#formatted_value ⇒ String
private
Value formatted according to format option.
-
#initialize(name:, value:, format: :number, icon: nil, live: false) ⇒ MetricCardComponent
constructor
A new instance of MetricCardComponent.
-
#label ⇒ String
private
Humanized metric label.
-
#live? ⇒ Boolean
private
True when the metric should expose a live target.
-
#live_target_id ⇒ String
private
Stable Turbo Stream target id.
Constructor Details
#initialize(name:, value:, format: :number, icon: nil, live: false) ⇒ MetricCardComponent
Returns a new instance of MetricCardComponent.
12 13 14 15 16 17 18 |
# File 'app/components/iron_admin/dashboards/metric_card_component.rb', line 12 def initialize(name:, value:, format: :number, icon: nil, live: false) @name = name @value = value @format = format @icon = icon @live = live end |
Instance Attribute Details
#icon ⇒ String? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Heroicon name.
50 51 52 |
# File 'app/components/iron_admin/dashboards/metric_card_component.rb', line 50 def icon @icon end |
Instance Method Details
#formatted_value ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Value formatted according to format option.
22 23 24 25 26 27 28 |
# File 'app/components/iron_admin/dashboards/metric_card_component.rb', line 22 def formatted_value case @format when :currency then helpers.number_to_currency(@value) when :percentage then helpers.number_to_percentage(@value, precision: 1) else helpers.number_with_delimiter(@value) end end |
#label ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Humanized metric label.
32 33 34 |
# File 'app/components/iron_admin/dashboards/metric_card_component.rb', line 32 def label @name.to_s.humanize end |
#live? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns True when the metric should expose a live target.
38 39 40 |
# File 'app/components/iron_admin/dashboards/metric_card_component.rb', line 38 def live? @live end |
#live_target_id ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Stable Turbo Stream target id.
44 45 46 |
# File 'app/components/iron_admin/dashboards/metric_card_component.rb', line 44 def live_target_id "metric_#{@name.to_s.parameterize(separator: "_")}" end |