Class: Www::SnowMeltingCalculatorComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Www::SnowMeltingCalculatorComponent
- Defined in:
- app/components/www/snow_melting_calculator_component.rb
Overview
Snow Melting Operating Cost Calculator
Calculates estimated operating costs based on coverage type, dimensions, runtime, and electricity rates
Usage:
<%# Basic usage %>
<%= render Www::SnowMeltingCalculatorComponent.new %>
<%# With custom defaults %>
<%= render Www::SnowMeltingCalculatorComponent.new(default_length: 30, default_hours: 8) %>
Constant Summary collapse
- WATTS_PER_SQFT =
Snow melting systems use 50W per square foot
50- DEFAULT_KWH_CENTS =
Default kwh cents.
16.26- TRANSLATIONS =
Translations.
{ en: { title: 'Operating Cost Calculator for Snow Melting', driveway_size: 'Driveway Size', single_car: 'Single Car Driveway (10 ft. wide)', double_car: 'Double Car Driveway (20 ft. wide)', triple_car: 'Triple Car Driveway (30 ft. wide)', custom: 'Custom Size', coverage_type: 'Coverage Type', full_coverage: 'Full Coverage — Heat the entire driveway', tire_tracks: 'Tire Tracks — Only heat paths for your car(s)', dimensions: 'Dimensions', width: 'Width', length: 'Length', tracks: '# Tracks', number_of_tracks: '# of Tracks', width_ft: 'Width (ft.)', length_ft: 'Length (ft.)', ft: 'ft.', zip_postal_code: 'Zip/Postal Code', my_location: 'Use my location', cents_per_kwh: 'Rate (¢/kWh)', snowfall_duration: 'Snowfall Duration', hour: 'hour', hours: 'hours', estimated_cost: 'Estimated Cost', per_hour: 'per hour', total_runtime: 'for runtime', rae_quote: 'A snow melting system is the ultimate set-it-and-forget-it solution. No more shoveling, no more slipping—just safe, clear walkways and driveways whenever you need them!' }, es: { title: 'Calculadora de Costo Operativo para Derretimiento de Nieve', driveway_size: 'Tamaño del Camino', single_car: 'Entrada de Un Auto (10 pies de ancho)', double_car: 'Entrada de Dos Autos (20 pies de ancho)', triple_car: 'Entrada de Tres Autos (30 pies de ancho)', custom: 'Tamaño Personalizado', coverage_type: 'Tipo de Cobertura', full_coverage: 'Cobertura Total — Calentar toda la entrada', tire_tracks: 'Huellas de Llantas — Solo calentar caminos para su(s) auto(s)', dimensions: 'Dimensiones', width: 'Ancho', length: 'Largo', tracks: '# Huellas', number_of_tracks: '# de Huellas', width_ft: 'Ancho (pies)', length_ft: 'Largo (pies)', ft: 'pies', zip_postal_code: 'Código Postal', my_location: 'Usar mi ubicación', cents_per_kwh: 'Tarifa (¢/kWh)', snowfall_duration: 'Duración de Nevada', hour: 'hora', hours: 'horas', estimated_cost: 'Costo Estimado', per_hour: 'por hora', total_runtime: 'por duración', rae_quote: 'Un sistema de derretimiento de nieve es la solución definitiva de configurar y olvidar. ¡Sin palear, sin resbalones—solo caminos seguros y despejados cuando los necesitas!' } }.freeze
- DRIVEWAY_SIZES =
Driveway sizes.
[ { id: 'single', tracks: 2, width: 10, length: 20, label_key: :single_car }, { id: 'double', tracks: 4, width: 20, length: 20, label_key: :double_car }, { id: 'triple', tracks: 6, width: 30, length: 20, label_key: :triple_car }, { id: 'custom', tracks: nil, width: nil, length: nil, label_key: :custom } ].freeze
Instance Attribute Summary collapse
-
#sp_area_name ⇒ String
readonly
SmartPlan area name, defaults to 'project'.
-
#sp_project_link ⇒ Object
readonly
Returns the value of attribute sp_project_link.
Instance Method Summary collapse
-
#calculate_default_kwh ⇒ Float
Default electricity rate in cents per kWh for the current locale.
-
#currency_symbol ⇒ ActiveSupport::SafeBuffer
Superscript currency symbol for the estimated cost display.
-
#driveway_sizes ⇒ Array<Hash>
Driveway size presets with localized names.
-
#horizontal? ⇒ Boolean
Whether the component renders in the horizontal (side-by-side) layout.
-
#initial_hourly_cost ⇒ Float
Calculate initial cost for server-side rendering.
-
#initial_total_cost ⇒ Float
Initial total cost for the default runtime.
-
#initialize(locale: :en, default_width: 10, default_length: 20, default_tracks: 2, default_hours: 6, default_kwh: nil, default_coverage: :tire_tracks, layout: :vertical, smartplan: nil) ⇒ SnowMeltingCalculatorComponent
constructor
A new instance of SnowMeltingCalculatorComponent.
-
#smartplan? ⇒ Boolean
Whether an integrated SmartPlan CTA panel was configured.
-
#sp_app_type ⇒ String?
SmartPlan application type from the product config.
-
#sp_carousel_options ⇒ Hash
Carousel options passed to the SmartPlan slides carousel.
-
#sp_icon ⇒ String?
SmartPlan panel icon from the product config.
-
#sp_link ⇒ String?
SmartPlan destination link from the product config.
-
#sp_rae_avatar ⇒ String?
Rae avatar image from the product config.
-
#sp_rae_quote ⇒ String?
Rae quote from the product config.
-
#sp_slides ⇒ Array
SmartPlan carousel slides, empty when unconfigured.
-
#sp_title ⇒ String?
SmartPlan panel title from the product config.
-
#t(key) ⇒ String
Translates a UI key for the component's locale.
-
#tire_tracks_default? ⇒ Boolean
Whether the default coverage is tire tracks (vs. full coverage).
Methods inherited from ApplicationComponent
#cms_link, #fetch_or_fallback, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_path, #post_url, #strip_tags
Constructor Details
#initialize(locale: :en, default_width: 10, default_length: 20, default_tracks: 2, default_hours: 6, default_kwh: nil, default_coverage: :tire_tracks, layout: :vertical, smartplan: nil) ⇒ SnowMeltingCalculatorComponent
Returns a new instance of SnowMeltingCalculatorComponent.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 100 def initialize( locale: :en, default_width: 10, default_length: 20, default_tracks: 2, default_hours: 6, default_kwh: nil, default_coverage: :tire_tracks, layout: :vertical, smartplan: nil ) super() @locale = locale.to_sym @default_width = default_width @default_length = default_length @default_tracks = default_tracks @default_hours = default_hours @default_kwh = default_kwh || calculate_default_kwh @default_coverage = default_coverage @layout = layout.to_sym @smartplan = smartplan resolve_smartplan_config if @smartplan end |
Instance Attribute Details
#sp_area_name ⇒ String (readonly)
Returns SmartPlan area name, defaults to 'project'.
157 158 159 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 157 def sp_area_name @sp_area_name end |
#sp_project_link ⇒ Object (readonly)
Returns the value of attribute sp_project_link.
157 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 157 attr_reader :sp_area_name, :sp_project_link |
Instance Method Details
#calculate_default_kwh ⇒ Float
Default electricity rate in cents per kWh for the current locale.
Falls back to DEFAULT_KWH_CENTS when no average rate is available.
172 173 174 175 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 172 def calculate_default_kwh rate = ElectricityRate.get_average_rate_for_locale(@locale) rate ? (rate * 100).round(2) : DEFAULT_KWH_CENTS end |
#currency_symbol ⇒ ActiveSupport::SafeBuffer
Superscript currency symbol for the estimated cost display.
218 219 220 221 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 218 def currency_symbol symbol = helpers.canada? ? 'C$' : '$' %(<span style="font-size:.55em;vertical-align:baseline;position:relative;top:-.45em;font-weight:500;color:#6c757d">#{symbol}</span>).html_safe end |
#driveway_sizes ⇒ Array<Hash>
Driveway size presets with localized names.
195 196 197 198 199 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 195 def driveway_sizes DRIVEWAY_SIZES.map do |size| size.merge(name: t(size[:label_key])) end end |
#horizontal? ⇒ Boolean
Whether the component renders in the horizontal (side-by-side) layout.
127 128 129 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 127 def horizontal? @layout == :horizontal end |
#initial_hourly_cost ⇒ Float
Calculate initial cost for server-side rendering
203 204 205 206 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 203 def initial_hourly_cost sqft = calculate_sqft calculate_hourly_cost(sqft, @default_kwh) end |
#initial_total_cost ⇒ Float
Initial total cost for the default runtime.
211 212 213 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 211 def initial_total_cost initial_hourly_cost * @default_hours end |
#smartplan? ⇒ Boolean
Whether an integrated SmartPlan CTA panel was configured.
134 135 136 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 134 def smartplan? @smartplan.present? end |
#sp_app_type ⇒ String?
Returns SmartPlan application type from the product config.
143 144 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 143 def sp_app_type = @sp_config&.dig(:application_type) # @return [String, nil] SmartPlan destination link from the product config |
#sp_carousel_options ⇒ Hash
Carousel options passed to the SmartPlan slides carousel.
162 163 164 165 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 162 def { type: 'fade', perPage: 1, perMove: 1, arrows: true, pagination: true, autoplay: true, interval: 4000, pauseOnHover: true, rewind: true, speed: 600 } end |
#sp_icon ⇒ String?
Returns SmartPlan panel icon from the product config.
141 142 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 141 def sp_icon = @sp_config&.dig(:icon) # @return [String, nil] SmartPlan application type from the product config |
#sp_link ⇒ String?
Returns SmartPlan destination link from the product config.
145 146 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 145 def sp_link = @sp_config&.dig(:smartplan_link) # @return [String, nil] Rae avatar image from the product config |
#sp_rae_avatar ⇒ String?
Returns Rae avatar image from the product config.
147 148 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 147 def sp_rae_avatar = @sp_config&.dig(:rae_avatar) # @return [String, nil] Rae quote from the product config |
#sp_rae_quote ⇒ String?
Returns Rae quote from the product config.
149 150 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 149 def sp_rae_quote = @sp_config&.dig(:rae_quote) # @return [Array] SmartPlan carousel slides, empty when unconfigured |
#sp_slides ⇒ Array
Returns SmartPlan carousel slides, empty when unconfigured.
151 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 151 def = @sp_config&.dig(:carousel_slides) || [] |
#sp_title ⇒ String?
Returns SmartPlan panel title from the product config.
139 140 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 139 def sp_title = @sp_config&.dig(:title) # @return [String, nil] SmartPlan panel icon from the product config |
#t(key) ⇒ String
Translates a UI key for the component's locale.
181 182 183 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 181 def t(key) TRANSLATIONS.dig(@locale, key) || TRANSLATIONS.dig(:en, key) || key.to_s.humanize end |
#tire_tracks_default? ⇒ Boolean
Whether the default coverage is tire tracks (vs. full coverage).
188 189 190 |
# File 'app/components/www/snow_melting_calculator_component.rb', line 188 def tire_tracks_default? @default_coverage == :tire_tracks end |