class InlineSvg::TransformPipeline::Transformations::DataAttributes
Public Instance Methods
transform(doc)
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations/data_attributes.rb, line 3 def transform(doc) with_svg(doc) do |svg| with_valid_hash_from(self.value).each_pair do |name, data| svg["data-#{dasherize(name)}"] = data end end end
Private Instance Methods
dasherize(string)
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations/data_attributes.rb, line 17 def dasherize(string) string.to_s.gsub(/_/, "-") end
with_valid_hash_from(hash)
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations/data_attributes.rb, line 13 def with_valid_hash_from(hash) Hash.try_convert(hash) || {} end