Sha256: 9e4af526f223e9a5aed1047dc8bb65273279d2bfd660c58daafdf3632ea3ed45

Contents?: true

Size: 457 Bytes

Versions: 2

Compression:

Stored size: 457 Bytes

Contents

# frozen_string_literal: true

class StimulusReflex::DomElement
  attr_reader :attributes

  delegate :[], to: :"@attributes"

  def initialize(attrs = {})
    @attributes = HashWithIndifferentAccess.new(attrs || {}).freeze
  end

  def dataset
    @dataset ||= attributes.each_with_object(HashWithIndifferentAccess.new) { |(key, value), memo|
      next unless key.start_with?("data-")
      memo[key.delete_prefix("data-")] = value
    }.freeze
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stimulus_reflex-1.1.1 lib/stimulus_reflex/dom_element.rb
stimulus_reflex-1.1.0 lib/stimulus_reflex/dom_element.rb