Class: Icons::Icon
- Inherits:
-
Object
- Object
- Icons::Icon
- Includes:
- Configurable
- Defined in:
- lib/icons/icon.rb,
lib/icons/icon/file_path.rb,
lib/icons/icon/attributes.rb,
lib/icons/icon/configurable.rb
Defined Under Namespace
Modules: Configurable Classes: Attributes, FilePath
Instance Method Summary collapse
-
#initialize(name:, library:, arguments:, variant: nil) ⇒ Icon
constructor
A new instance of Icon.
-
#svg ⇒ String
Returns the rendered SVG markup for the icon.
Constructor Details
#initialize(name:, library:, arguments:, variant: nil) ⇒ Icon
Returns a new instance of Icon.
17 18 19 20 21 22 23 24 |
# File 'lib/icons/icon.rb', line 17 def initialize(name:, library:, arguments:, variant: nil) @config = Icons.configuration @name = name @library = library.to_sym @variant = (variant || set_variant)&.to_sym @arguments = arguments end |
Instance Method Details
#svg ⇒ String
Returns the rendered SVG markup for the icon
32 33 34 35 36 37 38 39 |
# File 'lib/icons/icon.rb', line 32 def svg Nokogiri::HTML::DocumentFragment.parse(File.read(file_path)) .at_css("svg") .tap { |svg| attach_attributes(to: svg) } .to_html rescue Errno::ENOENT raise Icons::IconNotFound, end |