Class: LucideRuby::Icon

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

Constant Summary collapse

SVG_CONTENT_REGEX =
/<svg[^>]*>(.*)<\/svg>/m

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **options) ⇒ Icon



9
10
11
12
# File 'lib/lucide_ruby/icon.rb', line 9

def initialize(name, **options)
  @name = self.class.normalize_name(name)
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/lucide_ruby/icon.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/lucide_ruby/icon.rb', line 7

def options
  @options
end

Class Method Details

.extract_inner_html(svg_content) ⇒ Object



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

def self.extract_inner_html(svg_content)
  match = svg_content.match(SVG_CONTENT_REGEX)
  match ? match[1].strip : ""
end

.normalize_name(name) ⇒ Object



20
21
22
# File 'lib/lucide_ruby/icon.rb', line 20

def self.normalize_name(name)
  name.to_s.strip.downcase.tr("_", "-")
end

Instance Method Details

#renderObject



14
15
16
17
18
# File 'lib/lucide_ruby/icon.rb', line 14

def render
  inner_html = load_inner_html
  attributes = svg_attributes
  build_svg(inner_html, attributes)
end