Class: Healthicons::Transform

Inherits:
Object
  • Object
show all
Defined in:
lib/healthicons/transform.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{ 'aria-hidden' => true, stroke: 'currentColor', focusable: false, role: 'img', size: 24 }.freeze
HEIGHT_AND_WIDTH =
%i[height width].freeze
KEYS_TO_REMOVE =
%i[height width variant viewbox xmlns].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(svg, options = {}) ⇒ Transform

Used when transforming a new SVG::XML icon

Parameters:

  • svg (String)
  • options (Hash) (defaults to: {})


25
26
27
28
# File 'lib/healthicons/transform.rb', line 25

def initialize(svg, options = {})
  @svg = parse_icon_content(svg)
  @options = cleanup_options(options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/healthicons/transform.rb', line 12

def options
  @options
end

#svgObject

Returns the value of attribute svg.



12
13
14
# File 'lib/healthicons/transform.rb', line 12

def svg
  @svg
end

Class Method Details

.call(svg, options = {}) ⇒ String

Parameters:

  • svg (String)
  • options (Hash) (defaults to: {})

Returns:

  • (String)


17
18
19
# File 'lib/healthicons/transform.rb', line 17

def self.call(svg, options = {})
  new(svg, options).render
end

Instance Method Details

#renderString

Generate and return the SVG’s altered XML contents

Returns:

  • (String)


33
34
35
36
37
38
39
# File 'lib/healthicons/transform.rb', line 33

def render
  return '' if @svg.blank?

  add_icon_options
  # used to ensure icons with missing </path> have it added to ensure IE compatibiltiy
  @svg&.to_html(&:no_empty_tags)
end