module ApplicationHelper
ApplicationHelper
View helpers for the weather UI. Each method receives domain value objects (from +Services::Domains::Weather+) and returns safe HTML or plain strings suitable for ERB templates.
Public methods
-
{#weather_condition_icon_tag} — +<img>+ for the condition icon, or a text +<span>+ fallback.
-
{#weather_hourly_label} — Display label for an hourly forecast column (“Now”, “14:00”, …).
-
{#weather_temp_bar_style} — Inline CSS +left/right+ for a temperature range bar.
-
{#weather_source_badge} — Tiny “API” / “Cache” indicator with a coloured dot.
Public Instance Methods
Source
# File app/helpers/application_helper.rb 21 def weather_condition_icon_tag(weather_condition, size: 24, css_class: "") 22 url = weather_condition_icon_url(weather_condition) 23 return tag.span(weather_condition.description, class: "text-zinc-500 text-xs") unless url 24 25 tag.img( 26 src: url, 27 alt: weather_condition.description, 28 width: size, 29 height: size, 30 loading: :lazy, 31 class: "inline-block #{css_class}".strip 32 ) 33 end
Renders a weather condition icon as an +<img>+ tag, falling back to a text +<span>+ when no icon URI is available.
@param weather_condition [Domains::Weather::WeatherCondition] @param size [Integer] pixel width and height (default 24) @param css_class [String] additional CSS classes for the +<img>+ @return [ActiveSupport::SafeBuffer]
Source
# File app/helpers/application_helper.rb 45 def weather_hourly_label(entry, index) 46 return "Now" if index == 0 47 return "--" if entry.display_date_time.blank? 48 49 parts = entry.display_date_time.to_s.split(" ") 50 parts.size > 1 ? parts.last : parts.first 51 end
Returns a short time label for one column in the hourly forecast grid.
-
Index 0 always returns
"Now". -
Otherwise extracts the time portion (after the space) from +entry.display_date_time+ (e.g.
"2025-06-15 14:00"→"14:00"). -
Returns
"--"when the timestamp is blank.
@param entry [Domains::Weather::HourlyForecastEntry] @param index [Integer] zero-based position in the forecast array @return [String]
Source
# File app/helpers/application_helper.rb 81 def weather_source_badge(result, key) 82 cached = result.from_cache?(key) 83 dot_class = cached ? "bg-zinc-500" : "bg-emerald-500/80 shadow-[0_0_6px_rgba(16,185,129,0.4)]" 84 label = cached ? "Cache" : "API" 85 86 tag.span(class: "flex items-center gap-1.5 text-[10px] font-normal text-zinc-500") do 87 tag.span(class: "w-1 h-1 rounded-full #{dot_class}") + label 88 end 89 end
Renders a small badge showing whether data for +key+ came from the live API (green dot + “API”) or from cache (grey dot + “Cache”).
@param result [Services::Application::WeatherByAddress::Result] @param key [Symbol] one of +:geocode+, +:current_weather+, +:hourly_forecast+, or +:daily_forecast+ @return [ActiveSupport::SafeBuffer]
Source
# File app/helpers/application_helper.rb 65 def weather_temp_bar_style(min_temp, max_temp, global_min, global_max) 66 range = global_max - global_min 67 return "left: 0%; right: 0%;" if range <= 0 68 69 left = ((min_temp - global_min) / range * 100).round 70 right = ((global_max - max_temp) / range * 100).round 71 "left: #{left}%; right: #{right}%;" 72 end
Computes inline CSS for positioning a temperature range bar within a global min/max scale. The returned string sets +left+ and +right+ percentages so the bar spans only the day’s range.
Returns "left: 0%; right: 0%;" when the global range is zero (all days share the same temperature).
@param min_temp [Numeric] day’s low temperature @param max_temp [Numeric] day’s high temperature @param global_min [Numeric] lowest temperature across all forecast days @param global_max [Numeric] highest temperature across all forecast days @return [String] inline CSS style string