Class: Www::SnowMeltingCalculatorComponent

Inherits:
ApplicationComponent show all
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

Examples:

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 =
16.26
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 =
[
  { 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 Method Summary collapse

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.

Parameters:

  • locale (Symbol) (defaults to: :en)

    :en or :es

  • default_width (Integer) (defaults to: 10)

    Default width in feet

  • default_length (Integer) (defaults to: 20)

    Default length in feet

  • default_tracks (Integer) (defaults to: 2)

    Default number of tire tracks

  • default_hours (Integer) (defaults to: 6)

    Default runtime hours

  • default_kwh (Float) (defaults to: nil)

    Default electricity rate in cents per kWh

  • default_coverage (Symbol) (defaults to: :tire_tracks)

    :full or :tire_tracks

  • layout (Symbol) (defaults to: :vertical)

    :vertical (default, card-style) or :horizontal (side-by-side for inline use)

  • smartplan (Hash, nil) (defaults to: nil)

    When provided, renders an integrated SmartPlan CTA panel.
    Keys: :product_type (:snow_melting), :area_name (String), :project_link (String)



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/components/www/snow_melting_calculator_component.rb', line 95

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 Method Details

#calculate_default_kwhObject



142
143
144
145
# File 'app/components/www/snow_melting_calculator_component.rb', line 142

def calculate_default_kwh
  rate = ElectricityRate.get_average_rate_for_locale(@locale)
  rate ? (rate * 100).round(2) : DEFAULT_KWH_CENTS
end

#currency_symbolObject



171
172
173
174
# File 'app/components/www/snow_melting_calculator_component.rb', line 171

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_sizesObject



155
156
157
158
159
# File 'app/components/www/snow_melting_calculator_component.rb', line 155

def driveway_sizes
  DRIVEWAY_SIZES.map do |size|
    size.merge(name: t(size[:label_key]))
  end
end

#horizontal?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'app/components/www/snow_melting_calculator_component.rb', line 119

def horizontal?
  @layout == :horizontal
end

#initial_hourly_costObject

Calculate initial cost for server-side rendering



162
163
164
165
# File 'app/components/www/snow_melting_calculator_component.rb', line 162

def initial_hourly_cost
  sqft = calculate_sqft
  calculate_hourly_cost(sqft, @default_kwh)
end

#initial_total_costObject



167
168
169
# File 'app/components/www/snow_melting_calculator_component.rb', line 167

def initial_total_cost
  initial_hourly_cost * @default_hours
end

#smartplan?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'app/components/www/snow_melting_calculator_component.rb', line 123

def smartplan?
  @smartplan.present?
end

#sp_app_typeObject



129
# File 'app/components/www/snow_melting_calculator_component.rb', line 129

def sp_app_type     = @sp_config&.dig(:application_type)

#sp_area_nameObject



134
# File 'app/components/www/snow_melting_calculator_component.rb', line 134

def sp_area_name    = @sp_area_name


137
138
139
140
# File 'app/components/www/snow_melting_calculator_component.rb', line 137

def sp_carousel_options
  { type: 'fade', perPage: 1, perMove: 1, arrows: true, pagination: true,
    autoplay: true, interval: 4000, pauseOnHover: true, rewind: true, speed: 600 }
end

#sp_iconObject



128
# File 'app/components/www/snow_melting_calculator_component.rb', line 128

def sp_icon         = @sp_config&.dig(:icon)


130
# File 'app/components/www/snow_melting_calculator_component.rb', line 130

def sp_link         = @sp_config&.dig(:smartplan_link)


135
# File 'app/components/www/snow_melting_calculator_component.rb', line 135

def sp_project_link = @sp_project_link

#sp_rae_avatarObject



131
# File 'app/components/www/snow_melting_calculator_component.rb', line 131

def sp_rae_avatar   = @sp_config&.dig(:rae_avatar)

#sp_rae_quoteObject



132
# File 'app/components/www/snow_melting_calculator_component.rb', line 132

def sp_rae_quote    = @sp_config&.dig(:rae_quote)

#sp_slidesObject



133
# File 'app/components/www/snow_melting_calculator_component.rb', line 133

def sp_slides       = @sp_config&.dig(:carousel_slides) || []

#sp_titleObject



127
# File 'app/components/www/snow_melting_calculator_component.rb', line 127

def sp_title        = @sp_config&.dig(:title)

#t(key) ⇒ Object



147
148
149
# File 'app/components/www/snow_melting_calculator_component.rb', line 147

def t(key)
  TRANSLATIONS.dig(@locale, key) || TRANSLATIONS.dig(:en, key) || key.to_s.humanize
end

#tire_tracks_default?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'app/components/www/snow_melting_calculator_component.rb', line 151

def tire_tracks_default?
  @default_coverage == :tire_tracks
end