Class: Healthicons::Icon

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

Constant Summary collapse

VARIANTS =
%i[outline solid].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(icon, options = {}) ⇒ Icon

Instantize an icons attributes

Parameters:

  • icon (String)

    The icon image name

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

    (optional)



23
24
25
26
27
# File 'lib/healthicons/icon.rb', line 23

def initialize(icon, options = {})
  @variant = variant_check(options[:variant])
  @name = icon.to_s
  @options = options
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/healthicons/icon.rb', line 8

def name
  @name
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/healthicons/icon.rb', line 8

def options
  @options
end

#variantObject

Returns the value of attribute variant.



8
9
10
# File 'lib/healthicons/icon.rb', line 8

def variant
  @variant
end

Class Method Details

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

Generate a new instance of Healthicons and render the SVG icon

Parameters:

  • icon (String)

    The icon image name

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

    (optional)

Returns:

  • (String)

    the rendered icons SVG/XML contents



15
16
17
# File 'lib/healthicons/icon.rb', line 15

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

Instance Method Details

#renderString

Return the SVG icons contents

Returns:

  • (String)


32
33
34
35
36
# File 'lib/healthicons/icon.rb', line 32

def render
  return '' if svg_file_contents.blank?

  Healthicons::Transform.call(svg_file_contents, @options)
end