Class: Charming::Components::Audio
- Inherits:
-
Charming::Component
- Object
- View
- Charming::Component
- Charming::Components::Audio
- Defined in:
- lib/charming/presentation/components/audio.rb
Overview
Audio is a one-line playback-status indicator for a Audio::Player. It reads the player’s ‘playing?` state and renders a play/stop glyph with an optional label; pair it with a controller timer (or `on_task` re-render) to keep it live.
Note: this view component (‘Charming::Components::Audio`) is distinct from the playback engine namespace (`Charming::Audio`) — the component only displays state, the engine spawns the sound.
Instance Method Summary collapse
-
#initialize(player:, label: nil, theme: nil) ⇒ Audio
constructor
player is the Audio::Player whose state is shown.
-
#render ⇒ Object
Renders ‘▶`/`■` for playing/stopped, followed by the label when present.
Methods inherited from Charming::Component
Methods inherited from View
Constructor Details
#initialize(player:, label: nil, theme: nil) ⇒ Audio
player is the Audio::Player whose state is shown. label is an optional suffix (e.g. the track name) appended after the glyph. theme is the active theme, forwarded to the view layer.
16 17 18 19 20 |
# File 'lib/charming/presentation/components/audio.rb', line 16 def initialize(player:, label: nil, theme: nil) super(theme: theme) @player = player @label = label end |
Instance Method Details
#render ⇒ Object
Renders ‘▶`/`■` for playing/stopped, followed by the label when present.
23 24 25 26 27 28 |
# File 'lib/charming/presentation/components/audio.rb', line 23 def render glyph = @player. ? "▶" : "■" return glyph unless @label "#{glyph} #{@label}" end |